我在流星应用程序中有一个任务集合。我想将任务从“待办事项”推到“做”和“完成”statuses
我已经将它们放在列表中,并在 DOM 中使用它们的 id
创建了一个meteor方法来更新一个Task,叫做method,没用。什么都没发生,任务不会更新。
所以,我尝试直接调用 Task.update 方法
Meteor.methods({
create : function(json){Task.insert(json);},
update : function(id, conditions){Task.update(id, {$set : conditions});}
});
Template.todo.events({
'click .submit' : function(){
console.log("event called",this._id);
//Meteor.call('update',(this._id, {'status':'doing'}));
Task.update(this._id, {'status':'doing'});
}
});
当 Task.update(this._id, {'status':'doing'});
叫做。集合中的描述字段为空,仅更新状态字段。
Task.update 之前
{ "_id" : "er6Rqvdj8P373cPM5", "status" : "doing" , "description" : "work out and eat green chillies"}
后Task.update("er6Rqvdj8P373cPM5",{"status":"done"})
{ "_id" : "er6Rqvdj8P373cPM5", "status" : "done" }
打电话时update : function(id, conditions){Task.update(id, {$set : conditions});}
我在流星日志中收到以下错误
调用方法 'update' MongoError 时出现异常:指定的修饰符无效:$set
Exception while invoking method 'update' MongoError: Invalid modifier specified: $set
at Object.Future.wait (/Users/otto/.meteor/tools/275efdf2db/lib/node_modules/fibers/future.js:322:15)
at _Mongo.update (app/packages/mongo-livedata/mongo_driver.js:269:12)
at _.each.Meteor.Collection.(anonymous function) [as update] (app/packages/mongo-livedata/collection.js:354:32)
at Meteor.methods.update (app/alacrity.js:39:45)
at _.extend.protocol_handlers.method.exception (app/packages/livedata/livedata_server.js:593:30)
at _.extend.withValue (app/packages/meteor/dynamics_nodejs.js:31:17)
at app/packages/livedata/livedata_server.js:592:46
at _.extend.withValue (app/packages/meteor/dynamics_nodejs.js:31:17)
at _.extend.protocol_handlers.method (app/packages/livedata/livedata_server.js:591:37)
at _.extend.processMessage.processNext (app/packages/livedata/livedata_server.js:484:43)
- - - - -
at Object.exports.toError (/Users/otto/.meteor/packages/mongo-livedata/405d21f01568c045554ee5b99d2bea88a5249feb/.npm/node_modules/mongodb/lib/mongodb/utils.js:108:11)
at null.<anonymous> (/Users/otto/.meteor/packages/mongo-livedata/405d21f01568c045554ee5b99d2bea88a5249feb/.npm/node_modules/mongodb/lib/mongodb/collection.js:477:24)
at g (events.js:192:14)
at EventEmitter.emit (events.js:126:20)
at Server.Base._callHandler (/Users/otto/.meteor/packages/mongo-livedata/405d21f01568c045554ee5b99d2bea88a5249feb/.npm/node_modules/mongodb/lib/mongodb/connection/base.js:130:25)
at Server.connect.connectionPool.on.server._serverState (/Users/otto/.meteor/packages/mongo-livedata/405d21f01568c045554ee5b99d2bea88a5249feb/.npm/node_modules/mongodb/lib/mongodb/connection/server.js:517:20)
at MongoReply.parseBody (/Users/otto/.meteor/packages/mongo-livedata/405d21f01568c045554ee5b99d2bea88a5249feb/.npm/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:127:5)
at Server.connect.connectionPool.on.server._serverState (/Users/otto/.meteor/packages/mongo-livedata/405d21f01568c045554ee5b99d2bea88a5249feb/.npm/node_modules/mongodb/lib/mongodb/connection/server.js:476:22)
at EventEmitter.emit (events.js:96:17)
at _connect (/Users/otto/.meteor/packages/mongo-livedata/405d21f01568c045554ee5b99d2bea88a5249feb/.npm/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:175:13)
虽然流星文档说:
// mark my first message as "important"
Messages.update(myMessages[0]._id, {$set: {important: true}});