如何将值从一个属性传递到相同 collection 的另一个属性?
How to pass value from an attribute to another attribute of the same collection?
我的 'Jobs' collection:
我有这个扩展属性
var job = _.extend(jobAttributes, {
userId: user._id,
author: user.profile.name.toLowerCase(),
submitted: new Date(),
commentsCount: 0,
upvoters: [],
votes: 10,
apply: 0,
tweets: 0,
views: 0,
day1: 2,
day2: 0
});
我想做的是将值从 'Day1' 发送到 'Day2'
我为此做了一个'SyncedCron'
SyncedCron.add({
name: 'Update Example',
schedule: function(parser) {
return parser.text('every 2 minutes');
},
job: function() {
var one = this.day1;
Jobs.update({'day2': one});
}
});
但是我没有更新属性,而是收到了这个错误:
Error: Invalid modifier. Modifier must be an object.
问题出在 Jobs.update({'day2': one});
。
collection.update(selector, modifier, [options], [callback])
必须提供选择器和修饰符。
我使用类似这样的方法在插入自身时根据另一个字段填充字段。
我已经定义了架构,例如..
Jobs = new Mongo.Collection("jobs");
Jobs.schema = new SimpleSchema({
day1: {
type: SimpleSchema.Integer,
},
day2: {
type: Number,
autoValue: function() {
if (this.isInsert) {
return this.siblingField("day1").value;
}
}
}
});
Jobs.attachSchema(Jobs.schema);
我的 'Jobs' collection:
我有这个扩展属性 var job = _.extend(jobAttributes, {
userId: user._id,
author: user.profile.name.toLowerCase(),
submitted: new Date(),
commentsCount: 0,
upvoters: [],
votes: 10,
apply: 0,
tweets: 0,
views: 0,
day1: 2,
day2: 0
});
我想做的是将值从 'Day1' 发送到 'Day2'
我为此做了一个'SyncedCron'
SyncedCron.add({
name: 'Update Example',
schedule: function(parser) {
return parser.text('every 2 minutes');
},
job: function() {
var one = this.day1;
Jobs.update({'day2': one});
}
});
但是我没有更新属性,而是收到了这个错误:
Error: Invalid modifier. Modifier must be an object.
问题出在 Jobs.update({'day2': one});
。
collection.update(selector, modifier, [options], [callback])
必须提供选择器和修饰符。
我使用类似这样的方法在插入自身时根据另一个字段填充字段。 我已经定义了架构,例如..
Jobs = new Mongo.Collection("jobs");
Jobs.schema = new SimpleSchema({
day1: {
type: SimpleSchema.Integer,
},
day2: {
type: Number,
autoValue: function() {
if (this.isInsert) {
return this.siblingField("day1").value;
}
}
}
});
Jobs.attachSchema(Jobs.schema);