2014-12-10 54 views
1

在我的Meteor應用程序中使用upsert時出現錯誤。我有一個權限集合...Meteor upsert返回錯誤

Parts = new Mongo.Collection('parts'); 

if (Meteor.isServer) { 
    Parts.allow({ 
    insert : function() { 
     return true; 
    }, 
    update : function() { 
     return true; 
    }, 
    remove : function() { 
     return true; 
    } 
    }); 
} 

和一個upsert方法,用於檢查是否已創建帶有「partName」的文檔。

Meteor.call('partsUpsert', partName, content); 

Meteor.methods({ 
    partsUpsert: function (partName, content) { 
     Parts.upsert(
      check(content, Number), 
      check(partName, String), 
      {name: partName}, 
      { 
       $set: {vertices: content} 
      } 
     ); 
    } 
}); 

如果它尚未創建,它應該插入一個新的文檔到數據庫中。但我不斷收到服務器錯誤Exception while invoking method 'partsUpsert' Error: Invalid modifier. Modifier must be an object.

我已經嘗試修改代碼,但沒有任何工作。

回答

2

檢查是方法的一部分,而不是upsert。試試這個:

Meteor.methods({ 
    partsUpsert: function (partName, content) { 
    check(content, Number); 
    check(partName, String); 

    return Parts.upsert({name: partName}, {$set: {vertices: content}}); 
    } 
}); 
+0

工作。非常感謝! – 2014-12-11 00:14:58