【发布时间】:2020-12-05 03:53:04
【问题描述】:
她是我的猫鼬用户模式代码:
var mongoose = require('mongoose');
var userSchema = new mongoose.Schema({
email: {
type: String,
unique: true,
required: true
},
name: {
type: String,
required: true
},
Addtasks : [{
website: String,
otherdetails: String,
exampleRadios: String,
deadline: Date,
Date: String,
fileName: String,
Bigpaths:[]
}]
});
module.exports = mongoose.model('User', userSchema);
这是以json格式存储的mongodb数据:
{
"_id" : ObjectId("5f378bec5bd30f3248ffae59"),
"email" : "vikasthapar95@gmail.com",
"name" : "Vikas Yadav",
"Addtasks" : [
{
"website" : "grumpytext.com",
"keywords" : "article importance, article generation, article quality",
"words" : 1234567,
"topic" : "How article is generated?",
"_id" : ObjectId("5f379c7164a77a338483704c"),
"Bigpaths" : [
{
"path" : "public\\files\\chrome.VisualElementsManifest.xml",
"name" : "chrome.VisualElementsManifest.xml"
},
{
"path" : "public\\files\\chrome_proxy.exe",
"name" : "chrome_proxy.exe"
},
{
"path" : "public\\files\\master_preferences",
"name" : "master_preferences"
}
]
}
],
}
现在我想要的是仅迭代位于 Addtasks 数组内的 Bigpaths 嵌套数组,并从中获取其通过循环的每个对象的数据。我怎样才能做到这一点?我尝试过一种 populate() 的东西,但似乎没有帮助。请帮忙!!
期望的结果:
[
{
"path" : "public\\files\\chrome.VisualElementsManifest.xml",
},
{
"path" : "public\\files\\chrome_proxy.exe",
},
{
"path" : "public\\files\\master_preferences",
}
]
UI 端(车把)的预期结果:
Path 1 = public\\files\\chrome.VisualElementsManifest.xml
Path 2 = public\\files\\chrome_proxy.exe
Path 3 = public\\files\\master_preferences
【问题讨论】:
-
您能否在问题中添加预期结果
-
更新了预期结果。 @turrivisal。
标签: node.js arrays mongodb express mongoose