流星收集更新与传统 id [英] Meteor collection update with traditional id
本文介绍了流星收集更新与传统 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试做一个简单的更新
Im trying to do a simple update
Collection.update(id, {$set:{name:value}});
甚至
Collection.update({'_id':id}, {$set:{name:value}});
但是如果 id
是传统的 mongodb id,集合将不会更新.它似乎只适用于流星自己对唯一 ID 的实现.我该如何补救.流星可以接受mongo自己的id结构吗?
But the collection won't update if the id
is a traditional mongodb id. It only seems to work with meteors own implentation of unique id's. How can I remedy this. Is it possible for meteor to accept mongo's own id structure?
推荐答案
可以通过使用 new ObjectID 将您的 ID 转换为 mongodb 对象(在服务器端),然后进行更新.:
It's possible to convert your ID into a mongodb object (on the server side) by using new ObjectID and then do the update. :
var ObjectID, require;
require = __meteor_bootstrap__.require;
ObjectID = require("mongodb").ObjectID;
Meteor.methods({
SomeUpdate: function(upd) {
var id;
id = new ObjectID(upd['_id']);
return SomeDB.update({
_id: id
}, {
$set: {
field: value
}
}, function(res) {
return console.log(res);
});
}
});
这篇关于流星收集更新与传统 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文