如何在MongoDb中正确汇总此查询?

时间:2019-03-26 18:57:05

标签: mongodb

我有一个具有以下结构的集合:

SELECT * INTO VendorsBackup
from Vendors

作为输入,我有一个{ "_id" : .., "conversationID" : "conversation_1_id", "sender" : "user_2_Id", "msgbody" : "Hi there !", "ts" : "2019-03-25T23:12:14.235Z", } { "_id" : .., "conversationID" : "conversation_1_id", "sender" : "user_1_Id", "msgbody" : "Hello !", "ts" : "2019-03-26T02:45:44.627Z", } { "_id" : .., "conversationID" : "conversation_2_id", "sender" : "user_3_Id", "msgbody" : "Hi !", "ts" : "2019-03-26T02:45:44.627Z", } { "_id" : .., "conversationID" : "conversation_2_id", "sender" : "user_4_Id", "msgbody" : "Good morning !", "ts" : "2019-03-26T02:45:44.627Z", } 数组,我需要到达每个请求的sessionID的最后一条消息(按ts字段排序)。

我应该使用$first (aggregation)方法还是这种查询的低性能解决方案?
有人可以帮我写一个这样的查询的例子吗?

0 个答案:

没有答案