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
Asked
Active
Viewed 535 times
2
-
1Show how you are doing it – Alexander Staroselsky Sep 22 '21 at 14:40
1 Answers
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