2

I'm using MongoDB's Realm and trying to see if an ObjectId is equal to a string with the same characters. I've tried casting the ObjectId to a string and vice versa, but No matter what I try, it doesn't see them as equal even though the values are the EXACT same and they look the same when I log them. Please help lol

Josh
  • 51
  • 1

1 Answers1

0

ObjectId's can directly be used in comparisons with other ObjectId's - meaning there are <, >, <=, =>.

Also, the string representation of an ObjectId can be retrieved as

ObjectId.toString()

which returns the JavaScript representation in the form of a string literal "ObjectId(...)".

Given this

ObjectId("507f191e810c19729de860ea").str

would evaluate to

507f191e810c19729de860ea
Jay
  • 34,438
  • 18
  • 52
  • 81