爲什麼地球上這個更新失敗?這是基本的,我做過很多其他的時間。Meteor Mongo更新無效查詢
Meteor.users.update(id, {$set: {lastname: "Archer"}});
那上面的查詢,甚至有人從它原來是簡化,它仍然有同樣的問題。本來我是編程編譯更新:
console.log(obj);
console.log(id);
if (obj) collection.update(id, obj);
這是我從這些線精確的輸出:
Object {$set: Object}
$set: Object
lastname: "Archer"
__proto__: Object
__proto__: Object
main.js?b9104f881abb80f93da518738bf1bfb4cab0b2b6:68
YXeudfnHyKmsGXaEL
main.js?b9104f881abb80f93da518738bf1bfb4cab0b2b6:69
update failed: MongoError: invalid query
debug.js:41
的id
是正確的,如果obj
有什麼不對的地方,它會新聞給我!
現在,我很積極,這與我的allow
功能無關。在我的程序的這一部分的第一次測試中,我實際上做了得到了update not allowed
(或其它什麼)錯誤,但我修改了我的allow
函數以考慮到這一點,並且該錯誤消失了。
這是我的allow
函數。我有一個用戶系統,用戶可以有一個學生對象來「鏡像」它的名字信息,因此增加了複雜性。這部分功能只在某些情況下使用,並且不會改變津貼的行爲。
Meteor.users.allow({
update: function (userId, doc, fields, modifier) {
var allow = (userId && (doc._id === userId) && _.without(fields,
'firstname', 'lastname', 'student_ids', 'payment_ids', 'phones').length == 0) || Meteor.user().admin;
if (allow && modifier.$set && (_.contains(fields, 'firstname') || _.contains(fields, 'lastname'))) {
var user = Meteor.users.findOne(userId);
var obj = {};
if (modifier.$set.firstname) obj.firstname = modifier.$set.firstname;
if (modifier.$set.lastname) obj.lastname = modifier.$set.lastname;
if (obj) Students.update({_id: {$in: user.student_ids}, reflectsUser: true}, {$set: obj});
}
return allow;
}
});
這是在客戶端還是服務器上?如果在客戶端:是否在服務器上設置了適當的「允許」?另外,你是否確認'id'確實是一個有效的ID? –
它在客戶端上。是的,我已經打印出'id'並且它是正確的 – blaineh
您是否嘗試過使用{_id:id}而不是id?像這樣:'Meteor.users.update({_ id:id},{$ set:{lastname:「Archer」}});' – stubailo