我有以下架构。我在 mongodb 中使用 node.js
attributes: {
type: { type: 'string' },
title: { type:'string' },
description: { type:'string' },
is_active: { type:'boolean',defaultsTo:true },
createdBy: { type:'json' },
attachments:{ type:'array' }
}
arr = [{
'id':attResult.id,
'subtype':type,
'title' : attResult.title,
'body' : attResult.body,
'filetype' : attResult.filetype
}];
Run Code Online (Sandbox Code Playgroud)
我正在尝试将附件推送到文档唯一的“附件”数组中。
这是我的查询。
books.update(
{ id: refid },
{ $push: { attachments: arr } }
).done(function (err, updElem) {
console.log("updElem" + JSON.stringify(updElem));
});
Run Code Online (Sandbox Code Playgroud)
我的查询有什么问题,没有错误但没有更新附件。
我希望我的结果是这样的:
{
"_id" : 5,
"attachments": [
{
"id": "xxxxxxx",
"subtype": …Run Code Online (Sandbox Code Playgroud)