Tag: subdocument

如何使用$ push查询将数据插入到子文档中,而不是检索文档并将其保存回来

编辑:这实际上是工作 作为Mongoose – Subdocs:“Adding subdocs”文档说,我们可以使用push方法添加一个subdoc(即parent.children.push({ name: 'Liesl' }); ) 但我想走得更远,并希望使用$push操作符来插入子文档。 我有两个Schema: ThingSchema : var ThingSchema = mongoose.Schema({ name: { type: String, required: true }, description: { type: String } }); 和BoxSchema ,它是BoxSchema的子文档( things )数组的主文档: var BoxSchema = new mongoose.Schema({ name: { type: String, required: true }, description: { type: String }, things: { type: [ThingSchema] […]