Search code examples
javascriptmongodbmeteor

Mongo ObjectIDs not equal to eachother


new Mongo.ObjectID('18986769bd5eaaa42cb565b1') == new Mongo.ObjectID('18986769bd5eaaa42cb565b1')

returns false

new Mongo.ObjectID('18986769bd5eaaa42cb565b1').toString() == new Mongo.ObjectID('18986769bd5eaaa42cb565b1').toString()

returns true

Is this a bug, a feature or do I need to only work with these using valueOf() and convert it back from string when I need to work with the database?


Solution

  • You should take a look at this question, it might solve yours. Basically, they say that you need to use the equals method provided by the mongo library you are using