回送查询/对特定条件进行限制
我正在使用mongodb在strongloop
loopback
v2中构建一个非常复杂的查找查询,在这里我想限制搜索的某些部分。
例如,如果我有一个聊天室列表,并且只想为每个聊天室拉出最近200次最近的聊天,我将如何实现这一目标?
Messages.find({
"order": "created ASC",
"where": {
"or": [
{roomId: '111'}, // #todo: Limit this room to 200 messages
{roomId: '222'}, // #todo: Limit this room to 200 messages
]
}
}, ()=>{})
不要忘记某些房间可能没有消息...因此在此示例中,我无法进行全局limit: 400
。
回送查询/对特定条件进行限制
我正在使用mongodb在strongloop
loopback
v2中构建一个非常复杂的查找查询,在这里我想限制搜索的某些部分。
例如,如果我有一个聊天室列表,并且只想为每个聊天室拉出最近200次最近的聊天,我将如何实现这一目标?
Messages.find({
"order": "created ASC",
"where": {
"or": [
{roomId: '111'}, // #todo: Limit this room to 200 messages
{roomId: '222'}, // #todo: Limit this room to 200 messages
]
}
}, ()=>{})
不要忘记某些房间可能没有消息...因此在此示例中,我无法进行全局limit: 400
。