我有一个看起来像这样的模式:
{
"_id" : ObjectId("4f6af5c7065f92581a000013"),
....
"conversation" : [{
"_id" : ObjectId("4f6af5c7065f92581a000013"),
"msg" : "message1",
"userID" : 1
},{
"_id" : ObjectId("4f6af5c7065f92581a000016"),
"msg" : "message3",
"userID" : 1
},{
"_id" : ObjectId("4f6af5c7065f92581a000023"),
"msg" : "msg",
"userID" : 1
}]
}
我需要的是输出一个元素列表,其键 msg 的值包含'msg' 可以这样做吗?
db.dialogs.find({ "_id" : new ObjectId('4f6af5c7065f92581a000013'), "conversation.msg" : /msg/i })
但它会输出有关对象的所有信息。我需要的只是
{
"_id" : ObjectId("4f6af5c7065f92581a000023"),
"msg" : "msg",
"userID" : 1
}