This tool converts a BSON (extended json) syntax from MongoDB into JS so you
can use it for insertOne or insertMany if you wish.
TODOS:
- Output to console
- Create a custom parser
- Output to file (very difficult because new ObjectId isn't serialized as we want.)
- Test cases
- $oid parsing
- $numberInt parsing
- $numberFloat and etc. parsing
- $date parsing ?
- $date parsing
- Receive bulk inputs
-
Clone this repo and cd
-
Create
bson-input.txtand paste your content there like:[{ parentQueryGroupId: { $oid : "628fadb4d370987ac789c0cd" } }] -
Two ways to run this:
- Without Installing Bun
./bson-to-js - If bun is installed:
bun start
- Without Installing Bun
-
The output in
bson-output.txtshould be:[{ parentQueryGroupId: ObjectId("628fadb4d370987ac789c0cd") }]
If you want to convert in bulk, you can separate each using the keyword:
// BREAK
Input:
[{ parentQueryGroupId: { $oid : "628fadb4d370987ac789c0cd" } }]
// BREAK
[{ parentQueryGroupId: { $oid :
"628fadb4d370987ac789c0c1" } }]Output:
[{ parentQueryGroupId: ObjectId("628fadb4d370987ac789c0cd") }]
// BREAK
[{ parentQueryGroupId: ObjectId("628fadb4d370987ac789c0cd") }]