MongoDb-Node:用于聊天的Agregation node-mongo查询


石茶
2024-12-20 08:01:29 (2月前)


我是mongo的新手,想要获取聊天数据,让我解释一下。

我收集了一些消息:

_id:ID
观察:布尔
created_at:日期
文本:字符串
接收器:物件
发射器:物件
我想要所有……

2 条回复
  1. 0# 如果 | 2019-08-31 10-32



    您必须包含日期或已查看的数据

    $group

    阶段。



    试试这个。




    1. {
      $group:
      {
      _id: { tot:[“$emitter”, $receiver”] },
      text: { $addToSet:{text:”$text”,created:”$created.created_at”}},
      created_at:{$last:”$created.created_at”}
      }
      },

    2. </code>


    为什么会这样

    ids

    并需要

    tot

    田野和

    created

    作为对象?


登录 后才能参与评论