Javascript meteor:为嵌套文档添加一些值
我正在尝试向嵌套架构添加值:Javascript meteor:为嵌套文档添加一些值,javascript,meteor,Javascript,Meteor,我正在尝试向嵌套架构添加值: groups = new SimpleSchema({ title: { type: String, optional: true }, element: { type: [elements], optional: true } }); elements = new SimpleSchema({ description:{ type: String, optional: true }, anything: {
groups = new SimpleSchema({
title: { type: String, optional: true },
element: { type: [elements], optional: true }
});
elements = new SimpleSchema({
description:{ type: String, optional: true },
anything: { type: String, optional: true }
});
MongoDB.attachSchema(new SimpleSchema({
title: { type: String },
slug: { type: String, unique: true },
language: { type: String, defaultValue: "en" },
group: { type: [groups], optional: true },
}));
现在我只想向数据库中的现有条目添加一个新元素描述。我试过了,但没用
未捕获错误:当修饰符选项为true时,验证对象必须至少有一个运算符
var newElement = {
description: 'insert this as a new element description'
};
MongoDB.update({ _id: Id }, { $push: { 'group.element': newElement }}, function(error) { if(error) console.warn(error); });
将“group.element”用作$push参数是否正确
更新
我忘记了组的索引:$push:{'group.0.element':newElement}
此外,我还必须在模式中的组之前定义元素。是否尝试设置参数?安装了哪些软件包?我收到一个错误:
错误:slug字段的定义无效
您是否尝试设置$set参数?您安装了哪些软件包?我收到一个错误:错误:slug字段的定义无效