我是Mongo的新手并尝试将ArrayList值与mongoDB进行比较,结果我想要匹配值列表。
让我解释一下。我有一个带有一个文档的集合。
db.contact.find().pretty(){
"_id" : ObjectId("5718ae778310b8eb61aed7b0"),
"contacts" : [
{
"name" : "Sunny",
"phone" : "9417702107"
},
{
"name" : "Sukhpal",
"phone" : "9015719419"
},
{
"name" : "anurag",
"phone" : "9988776655"
},
{
"name" : "vivek",
"phone" : "8826565107"
}
]}
这是我的Json with Array List,我将使用HTTPs:
{
"contacts":[
{
"name":"anurag",
"phone":"9988776655"
},
{
"name":"Gurwinder",
"phone":"9015566789"
}
]}
所以现在我不知道如何查询以及如何在mongo中循环播放数组。这是我的Node.js Mongoos代码:
exportcontact = function(req, res, next)
{
var response = {};
Contacts.find({},function(err,data){
// Mongo command to fetch all data from collection.
if(err) {
response = {"error" : true,"message" : "Error fetching data"};
}
else if(!data)
{
response = {"error" : true,"message" : "No Record Found"};
}
else
{
var contactlist = req.body.contacts;
//************ DON'T KNOW WHAT TO DO HERE***************//
response = {"List": };
}
res.json(response);
});
};
请帮忙。