【发布时间】:2014-06-07 05:46:19
【问题描述】:
我有以下架构。我正在将 node.js 与 mongodb 一起使用
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
}];
我正在尝试将附件推送到文档独有的“附件”数组中。
这是我的查询。
books.update(
{ id: refid },
{ $push: { attachments: arr } }
).done(function (err, updElem) {
console.log("updElem" + JSON.stringify(updElem));
});
我的查询有什么问题,没有错误但没有更新附件。
我希望我的结果是这样的:
{
"_id" : 5,
"attachments": [
{
"id": "xxxxxxx",
"subtype": "book",
"title": "xxxx",
"body": "xxxx" ,
"filetype" : "xxxxx"
},
{
"id": "xxxxxxx",
"subtype": "book",
"title": "xxxx",
"body": "xxxx",
"filetype": "xxxxx"
}
]
}
【问题讨论】:
-
你在这里真正使用的是什么?也许是猫鼬?您的意思是“属性”是您的架构定义吗?还是定义实际上是一个名为“属性”的字段下的附加字段?