问题描述
我有一个Meteor应用程序,在命名模板中的列表项时,最初使用集合中每个记录的_id
字段.
I have a Meteor application whereby I initially use the _id
field from each record in my collection when naming list items in my template.
当获取_id
字段时,我将其转换为要在模板中使用的字符串.
When get the _id
field, I convert it to a string to use in the template.
现在,我想在Mongo中更新这些记录,并将_id
传递回Meteor.method
,但是它们仍为字符串格式,Mongo希望使用ObjectID().有没有简单的方法可以将此字符串转换为ObjectID()
?如果没有,我有什么选择?
Now I want to update these records in Mongo and am passing the _id
back to a Meteor.method
, but these are still in string format and Mongo is expecting an ObjectID(). Is there a simple way to convert this string to the ObjectID()
? If not, what alternatives do I have?
推荐答案
好,找到了!在/server
的Meteor方法函数中,执行以下操作以将其转换:
Ok, found it! On the /server
, within your Meteor method function do this to convert it:
var mid = new Mongo.ObjectID(str_id_sent_to_server);
这篇关于将字符串转换为Javascript(流星)中的Mongo ObjectID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!