2013-04-29 40 views
1

我在流星應用程序中有一個任務集合。 我要推從「待辦事項」任務,以「做」和「做」 statusesMeteor.js在調用Foo.update(id,{conditions})時會移除文檔字段

我已經得到了他們的名單與他們的ID在DOM

創建一個流星方法更新任務,所謂的方法,沒有工作。什麼都沒有發生,任務不會更新。

所以,我試圖調用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,{ '地位': '做'});

被調用。集合中的描述字段爲空,只有狀態字段被更新。

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});}

我收到以下錯誤流星日誌

異常而調用方法「更新'MongoError:In有效修改規定:$設置

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}}); 

http://docs.meteor.com/#meteor_user

回答

1

這取決於你使用什麼&修改,可能觸發此錯誤。

基本上,如果你使用:

Task.update(this._id, {'status':'doing'}); 

這將設置文件與this._id{status: 'doing'}

如果使用$set將只設置中指定的字段:

Task.update(this._id, { $set: {'status': 'doing'}}); 

也不必使用方法&可以直接在客戶端上完成。更多關於如何使用$設置的詳細信息,請參考mongodb docs

+0

我這樣做,現在 'Meteor.call( '更新',(字符串(this._id){$設置:{狀態: '做'}} )); 更新:功能(ID,條件){任務。更新(字符串(ID),條件);} 和我得到: '異常而調用方法 '更新' 錯誤:無效改性劑。修飾符必須是一個對象。 at _Mongo.update(app/packages/mongo-livedata /' – qwexar 2013-04-30 10:54:06

3

我猜你到現在爲止發現了這個錯誤,但是我將它發佈給其他可能面臨同樣問題的人。

此行有額外的括號:

Meteor.call('update',(this._id, {'status':'doing'})); 

它應該是這樣的:

Meteor.call('update',this._id, {'status':'doing'}); 

如果你得到這個消息:

MongoError: Invalid modifier specified: $set 

的問題將有可能與$ set旁邊的是什麼。在上面的情況下是「未定義」。

發生在我身上的今天:)