【发布时间】:2018-07-09 13:44:43
【问题描述】:
belwo 是我的收藏
"_id" : ObjectId("5b435afff64f913c51799334"),
"_class" : "com.games24x7.mongo.ChatMessageClanId",
"chatMessage" : [
{
"playerId" : NumberLong(230000034),
"message" : "Hi ",
"messageType" : "NORMAL",
"chatTime" : NumberLong("1530894311114"),
"chatSequence" : 1
},
{
"playerId" : NumberLong(230000034),
"message" : "Hi ",
"messageType" : "NORMAL",
"chatTime" : NumberLong("1530894311114"),
"chatSequence" : 2
},
{
"playerId" : NumberLong(230000034),
"message" : "Hi ",
"messageType" : "NORMAL",
"chatTime" : NumberLong("1530894311114"),
"chatSequence" : 3
},
{
"playerId" : NumberLong(230000034),
"message" : "Hi ",
"messageType" : "NORMAL",
"chatTime" : NumberLong("1530894311114"),
"chatSequence" : 4
}],
"clanId" : 1
我想检索以下格式的数据,例如:
"chatMessage" : [{
"playerId" : NumberLong(230000034),
"message" : "Hi ",
"messageType" : "NORMAL",
"chatTime" : NumberLong("1530894311114"),
"chatSequence" : 3
},
{
"playerId" : NumberLong(230000034),
"message" : "Hi ",
"messageType" : "NORMAL",
"chatTime" : NumberLong("1530894311114"),
"chatSequence" : 4
}]
我尝试过以下查询:
db.chatMessageClanId.find({clanId:1,"chatMessage.chatSequence":{$gt:2}}) db.chatMessageClanId.find({clanId:2,"chatMessage.chatSequence":{$gt:2}},{chatMessage:1})
【问题讨论】:
标签: arrays mongodb mongodb-query mongotemplate