![]() In mongosh, you can access the creation time of the ObjectId, using the ObjectId.getTimestamp() method.Third, the mongodb docs state there is two benefits to using ObjectId: Yes _id as raw string is convenient sometimes, but convenient in the similar way scripting language is convenient over typed one - you'll pay for it when project becomes large. Using Typescript and typing DB schema can remove much of the ambiguity around what your comparing. Second, and most relevant for me is I decided to use Typescript. Reasons:įirst, ObjectId is 12 bytes, not 24 bytes as pointed out. Why shouldn't I do this? Having reflected on this I decided to not use a stringification of ObjectId over ObjectId. I mean sure, I can see some potential advantages but I never understood or found any clear documentation outlining why they did this. I gather there was a very good reason MongoDB decided to use ObjectId over just strings. For example in NodeJS = is always false you have to use ObjectId.equals or =. It saves confusing about comparison in code if object identifiers are just always a strings.And I don't need to know a priori a given field is an ObjectId and special case it. If I grab an object identifier off the wire or out of some JSON document, I don't need to hydrate it into an ObjectId before doing comparison queries in a find or aggregation pipeline. ![]() In general the argument for, is it makes comparisons easier: ![]() For the required document _id field I'm considering using the string serialization of an ObjectId instead of MongoDB's default ObjectId (i.e. I'm starting an new MongoDB project (in NodeJS). There is this question which asks essentially the same question but is three questions in one and the 1/3 I'm after isn't really answered very well so I'm asking it again: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |