我有一系列项目ID,例如:
[ 'ExneN3NdwmGPgRj5o', 'hXoRA7moQhqjwtaiY' ]
在我的问题集中,我有一个名为' project'的字段,其中包含一个项目ID字符串。例如:
{
"_id" : "XPRbFupkJPmrmvcin",
"question" : "Vraag 13",
"answer" : "photo",
"project" : "ExneN3NdwmGPgRj5o",
"datetime_from" : ISODate("2017-01-10T08:01:00Z"),
"datetime_till" : ISODate("2017-01-10T19:00:00Z"),
"createdAt" : ISODate("2017-01-10T08:41:39.950Z"),
"notificationSent" : true
}
{
"_id" : "EdFH6bo2xBPht5kYW",
"question" : "sdfadsfasdf",
"answer" : "text",
"project" : "hXoRA7moQhqjwtaiY",
"datetime_from" : ISODate("2017-01-11T11:00:00Z"),
"datetime_till" : ISODate("2017-01-11T17:00:00Z"),
"createdAt" : ISODate("2017-01-10T10:21:42.147Z"),
"notificationSent" : false
}
现在我想return
所有问题集合的文档,其中Project(id)是数组中的值之一。
为了测试它是否有效,我首先尝试返回一个文档。 我是console.logging这样:
Questions.findOne({project: { $eq: projectArray }})['_id'];
但也试过这个:
Questions.findOne({project: { $in: [projectArray] }})['_id'];
但仍然未定义'
答案 0 :(得分:0)
请试一试。
Questions.find({project: { $in: projectArray }}) => for fetching all docs with those ids
Questions.findOne({project: { $in: projectArray }}) => if you want just one doc