mongoose如何给数组子集的子集插入数据 - CNode技术社区

mongoose如何给数组子集的子集插入数据
发布于 8 年前 作者 Gil2015 2736 次浏览 来自 问答

node后台做个博客评论功能,需要给子集push数据,百度了一下知道如何更新添加第一层数据,但是子集的子集不知如何添加更改。 望求教~

// 文章数据结构
const article = {
 content: '文章内容',
 author: '作者',
 comments: [
 {
	 commentsId: 123,
 replyContent: '评论内容',
 replyUser: '评论用户',
 itemComments: [
 {
		 itemCommentId: 456
 itemReplyContent: '子评论',
 itemreplyUser: '子评论人'
 }
 ]
 }
 ]
};
// 添加数组第一层数据
articleSchema.update({
 _id: articleId
}, {
 '$push': {
 'comment': {
 replyContent: '评论内容',
 replyUser: '评论用户',
 itemComments: []
 }
 }
}, err => {
 console.log(err);
});
1 回复

用Scheme.Types.Mixed

来自酷炫的 CNodeMD

回到顶部

AltStyle によって変換されたページ (->オリジナル) /