【发布时间】:2020-10-27 19:15:44
【问题描述】:
这是我的模型,并且已经在数据库中有一些文档。
我想将一个新的 Object 推送到现有帖子文档的 like_count 数组中,其中 postId 将与给定值匹配。
我是第一次使用 Mongoose。我已经搜索过,但没有找到像这样的用例。无法理解如何编写逻辑。需要帮助。
另外,告诉我我是如何定义Users 模型的,还是应该为那些数组对象使用子文档??
const Users = new mongoose.Schema({
username: { type: String, unique: true },
recent_posts: [
{
postId: String,
posted_at_timestamp: Number,
like_count: [
{
count: Number,
created_at: { type: Date, default: Date.now }
}
],
comment_count: [
{
count: Number,
created_at: { type: Date, default: Date.now }
}
]
}
],
})
【问题讨论】:
标签: node.js mongodb mongoose nosql