Compare Strings and ObjectIds in JSON Expressions
We have a use-case where we need to compare an ObjectId on a document to the ObjectId of the user's custom data doc. However, because the ID of the user's custom data object is returned as a string and not as an ObjectId, there is no way to make this comparison without creating a function just to compare the ObjectId and the string. The overhead of invoking a function just to call toString on the ObjectId is going to be a major problem, especially because we need to make this comparison 5 times for every single operation on our most heavily trafficked collection.
This could be easily solved by what should be a rather simple feature to add, an operator that could be used to compare an ObjectId to a string within JSON expressions.
I think the best justification for this addition is that there are several situations where you simply cannot get an ID in ObjectId form as it is only provided as a string, like the ID on user custom data docs.
![](https://secure.gravatar.com/avatar/67b95679a1ba8c5ee138793a9d8e058c?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)