以下是我的架构:
new Schema({
user: [{
email: { type: String },
contactList: [{
frndemail: { type: String },
msgList: [{
from : String,
to : String,
content : String,
time : String,
type: String,
subtype : String,
state: String
}],
unreadmsgList:[{
from : String,
to : String,
content : String,
time : String,
type: String,
subtype : String,
state: String
}]
}]
}]
});
在上述架构中,我试图在msgList中推送新消息,但是我的查询无法正常工作,我正在尝试如下操作:
MyModel.update({"user.email":"myemail@gmail.com","user.contactList.frndemail":"frndemail@gmail.com"}, {
$push:{"user.$.contactList.$.msgList":{
"from": "myemail@gmail.com",
"to": "frndemail@gmail.com",
"content": "abc",
"time": "1:00 PM",
"type": "",
"subtype": "",
"state": ""
}}
},
function(err,doc){
if (err) {
console.log("msg creation failed " +err);
} else {
console.log("msg created successfully "+doc);
}
});
如果有人为我更正此查询,请谢谢...