3

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.

When get the _id field, I convert it to a string to use in the template.

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?

1 Answer 1

9

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.