小编Ror*_*ory的帖子

如何在mongoose中更新嵌入文档中的嵌入文档?

我在node.js中构建一个使用mongodb和mongoose的API.目前我在嵌入式文档(Schema中的Schema)中有一个嵌入式文档,它根本没有持久存储到数据库中,我已尽力而为但没有运气.

我在mongoose中定义了Schema:

var BlogPostSchema = new Schema({
  creationTime: { type: Date, default: Date.now },
  author: { type: ObjectId, ref: "User" },
  title: { type: String },
  body: { type: String },
  comments: [CommentSchema]
});

var CommentSchema = new Schema({
  creationTime: { type: Date, default: Date.now },
  user: { type: ObjectId, ref: "User" },
  body: { type: String, default: "" },
  subComments: [SubCommentSchema]
});

var SubCommentSchema = new Schema({
  creationTime: { type: Date, default: Date.now },
  user: { type: ObjectId, ref: …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js mongodb-query

5
推荐指数
1
解决办法
2593
查看次数

标签 统计

mongodb ×1

mongodb-query ×1

mongoose ×1

node.js ×1