Support Extended JSON format
See original GitHub issueHi @pkosiec,
Awesome job at the library, it’s very useful.
I’m running into an issue. I’m inserting data from a JSON file. In the file I have an “_id” field which should be MongoDB ObjectId.
The issue is that it gets inserted as plain text.
This syntax should lead to the creation of ObjectIds:
{
"_id" : {"$oid":"5a68fdc3615eda645bc6bdec"}
}
But it throws an error locally: { MongoSeedingError: Error: key $oid must not start with '$'
I found that syntax here: https://stackoverflow.com/questions/51439955/mongoimport-id-is-not-an-objectid
Is there a way to end up with ObjectIds instead of plain text ids?
Thank you
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (9 by maintainers)
Top Results From Across the Web
MongoDB Extended JSON (v2)
Use Extended JSON v2.0 (Canonical mode) format for the metadata. Requires mongorestore version 4.2 or later that supports Extended JSON v2.0 ...
Read more >specifications/extended-json.rst at master - GitHub
MongoDB Extended JSON is a string format for representing BSON documents. This specification defines the canonical format for representing each BSON type in...
Read more >Extended JSON - GitHub Pages
Relaxed Mode: Relaxed representation that loses type information for BSON numeric types and uses a more human-readable representation of BSON dates. See the ......
Read more >MongoDB Extended JSON (v2)
MongoDB Extended JSON (v2) ... . Any JSON parser can parse these strict mode representations as key/value pairs; however, only the MongoDB internal...
Read more >MongoDB Extended JSON
JSON can only represent a subset of the types supported by BSON. To preserve type information, MongoDB adds the following extensions to the...
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 Free
Top 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
Hi @Fiyin-Anne, Because EJSON parsing is enabled by default for all JSON files, it should work normally. Just to double check: do you have something like this in your
json
file?If so, it should work.
The error you provided shouldn’t be related to the EJSON parsing mode. Anyway, currently there is no support for changing mode of EJSON parsing, however I will introduce it very shortly.
Hi @mtapdilli, I’m using EJSON parser from official MongoDB
bson
package. What I do ishttps://github.com/pkosiec/mongo-seeding/blob/master/core/src/populator/filesystem.ts#L125
However, maybe the relaxed mode messes things up?
Could you please try using
canonical
mode e.g. with modified mongo-seeding that uses this mode while parsing EJSON? If that will be the case, I can add additional parameters to configure EJSON parsing mode.Cheers!