in mongodb how can i find multiple documents at ones??
在mongodb中如何找到多个文档?
in my post method i have appoinments collection.when getting post data i want check they already in database using hour_responce
and date_responce
but how can i do with 2 documents.its working fine with only one docement.
在我的岗位方法中,我有任命。在获取post数据时,我希望在数据库中使用hour_responce和date_responce检查它们,但是我如何处理两个文档。它的工作很好,只有一个码头。
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----
- - - - 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] }
1 个解决方案
#1
0
You are using findOne method of your collection.
您正在使用您收集的findOne方法。
You can try with : find() method, and then iterate on your resultset to make your comparisons
您可以尝试使用:find()方法,然后在resultset上迭代来进行比较。
EDIT :
编辑:
req.collection.find({}).toArray(function(e,result){
});
#1
0
You are using findOne method of your collection.
您正在使用您收集的findOne方法。
You can try with : find() method, and then iterate on your resultset to make your comparisons
您可以尝试使用:find()方法,然后在resultset上迭代来进行比较。
EDIT :
编辑:
req.collection.find({}).toArray(function(e,result){
});