[英]Is this possible to extract an Object from nested array through mongoDB Query?
我在貓鼬中有以下架構。
var AttendanceSchema = new mongoose.Schema({
ownerId: mongoose.Schema.Types.ObjectId,
companyId: mongoose.Schema.Types.ObjectId,
months: [
{
currentSalary: {
type: Number,
default: 0
},
month: {
type: Date,
},
salary: {
type: Number,
default: 0
}
days: [
{
manuallyUpdated: {
type: Boolean,
default: false
},
date: {
type: Date,
},
perDaySalary: {
type: Number,
default: 0
},
status: {
type: String,
}
}
]
}
]
});
我想提取天數組中的單個對象。
注意:有days數組嵌套在months數組中,我已經使用$ pull來拉出那一天,但我想再次拉入並推入(更新的一天)。
我認為如果您知道days數組中的哪個元素需要信息,就可以執行此操作,因為days數組將由多個元素組成。
假設您需要數組中的第一個元素:
Attendance.findOne({_id: request.id}, function(err, foundAttendance){
console.log(foundAttendance.days[0].date);
}
您可以根據所需數據將0更改為所需的任何數字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.