document.toJSON doesn't toJSON _id
See original GitHub issueif you toJSON a mongoose model, the _id remains an object.
this is a problem if you’re trying to compare against an actual json representation of the same object.
Simple solution is to
JSON.parse(JSON.stringify(model))
but that’s real ugly.
Is there a good reason the id isn’t stringified? If not, I’ll fix up the toJSON in a PR.
Issue Analytics
- State:
- Created 11 years ago
- Reactions:4
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Bson Document to Json in Java - Stack Overflow
I use String id = ObjectId.get().toHexString(); rather than storing ObjectId directly. – Shadow Man. Apr 19, 2018 at 0:45.
Read more >JSON And BSON - MongoDB
Firstly, BSON documents may contain Date or Binary objects that are not natively representable in pure JSON. Second, each programming language has its...
Read more >C# calling tojson returns JSON that has"_id" - Google Groups
To work around this, I have been using Fields. Exclude("_id") but I'd like to retain this field in the json output. I have...
Read more >Converting between JSON and XML - Json.NET
Json.NET supports converting JSON to XML and vice versa using the XmlNodeConverter. Elements, attributes, text, comments, character data, ...
Read more >Working with JSON data in Google Standard SQL | BigQuery
This lets you store and query data that doesn't always adhere to fixed ... Row-level access policies cannot be applied on JSON columns....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
toJSON a mongoose model, the _id remains an object
It is easy to make mistakes when make test compare…In case this helpful to anyone, I had to create this perf-thinking lib to cast ObjectIDs to string.