Skip to content

A quick tool to turn Mongo's extended json to JS that can be used for insertOne.

Notifications You must be signed in to change notification settings

TPLCarloTaleon/bson-to-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bson-to-mongo-query

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

Getting Started

  1. Clone this repo and cd

  2. Create bson-input.txt and paste your content there like:

    [{ parentQueryGroupId: { $oid :
    "628fadb4d370987ac789c0cd" } }]
  3. Two ways to run this:

    • Without Installing Bun ./bson-to-js
    • If bun is installed: bun start
  4. The output in bson-output.txt should be:

    [{ parentQueryGroupId: ObjectId("628fadb4d370987ac789c0cd") }]

How to Convert in Bulk (WIP)

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") }]

About

A quick tool to turn Mongo's extended json to JS that can be used for insertOne.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published