【问题标题】:mongoDB chat system database structuremongoDB聊天系统数据库结构
【发布时间】:2023-04-06 17:08:01
【问题描述】:

我正在尝试使用 mongoDB 创建群聊系统,但支持 mongoose 对象类型我如何创建这样的模型(插入下图)?并查询这些数据?我试图创建架构但没有工作

sample of model (dummy)

【问题讨论】:

    标签: node.js mongodb mongoose mongoose-schema


    【解决方案1】:

    const chatSchema = new mongoose.Schema({ users: Array, texts:[{ user: String, text: String, time: Date, }] });

    试试这个架构。将加入群聊的用户将添加到users 字段中。文本将有作者(user)、文本(text)和日期(time)。

    【讨论】:

      猜你喜欢
      • 2017-09-19
      • 2018-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      • 2016-04-27
      • 1970-01-01
      • 2014-02-03
      相关资源
      最近更新 更多