在mongodb中如何找到多个文件?
在我的帖子方法中我有appoinments collection.when获取发布数据我想要检查他们已经在数据库中使用hour_responce
和date_responce
但我怎么能用2个文件。只有一个工作正常docement。
app.post('/collections/:collectionName', function(req, res, next) {
console.log(req.body[0])
if(req.params.collectionName == 'appoinments'){
req.collection.findOne({date_responce:req.body[0].date_responce,hour_responce:req.body[0].hour_responce}, function(e, result){
if(result){
console.log(result); console.log(e)
res.send(500,{error:"You Already have a Task on this Time Period"})
}
else{
req.collection.insert(req.body, {}, function(e, results){
if (e) return next(e)
res.send(results)
})
}
})
}
else{
req.collection.insert(req.body, {}, function(e, results){
if (e) return next(e)
res.send(results)
})
}
})
--- ---- UPDATE
{ toArray: [Function],
each: [Function],
next: [Function],
nextObject: [Function],
setReadPreference: [Function],
batchSize: [Function],
count: [Function],
stream: [Function],
close: [Function],
explain: [Function],
isClosed: [Function],
rewind: [Function],
limit: [Function],
skip: [Function],
hint: [Function],
maxTimeMS: [Function],
sort: [Function],
fields: [Function] }
答案 0 :(得分:0)
您正在使用集合的findOne方法。
您可以尝试使用:find()方法,然后迭代结果集以进行比较
编辑:
req.collection.find({}).toArray(function(e,result){
});