這是我的「羣組」數據如何在node和mongodb中查找?
{
"_id": {
"$oid": "58f7537ec422895572e988a1"
},
"name": "aaa",
"groupname": "group north,group south",
"mobilenumber": "0509867865",
"userid": "6035555c16"
}
我在這裏的「組」收集數據的
{
"_id": {
"$oid": "58e5eb3c035555c33f979daf"
},
"groupname": "group north",
"message": [
{
"val": "hai how are you",
"key": "1"
},
{
"val": "i am fine",
"key": "2"
}
]
},
{
"_id": {
"$oid": "3c035555c33f979daf58e5eb"
},
"groupname": "group south",
"message": [
{
"val": "testing",
"key": "1"
}
]
},
{
"_id": {
"$oid": "55c3c035533f979f58e5ebda"
},
"groupname": "group east",
"message": [
{
"val": "where are you from",
"key": "1"
}
]
}
在用戶組,我試圖讓mobilenumber
基於groupname
和我有兩個羣體:group north
和group south
。獲取組名後,我需要獲取消息。我怎麼寫這個來找到這個條件。我的目標是發送group north, group south
消息給用戶。
Usergroup.findOne({
mobilenumber: 0509867865
},
function(err, usergroup) {
if (err) {
return handleError(res, err);
}
if (!usergroup) {
return res.status(404).send('Not Found');
}
console.log(usergroup.groupname);
//group north ,group south
Group.find({
groupname:
},
function(err, group) {
if (err) {
return handleError(res, err);
}
return res.json(group);
});
});
什麼是你的mongo服務器版本? – Veeram
我正在使用mongolab –
http://docs.mlab.com/ops/#current-version。你能檢查使用此鏈接? – Veeram