Home > Blockchain >  What is the best practice for converting and storing a nested JSON file as a MongoDB document?
What is the best practice for converting and storing a nested JSON file as a MongoDB document?

Time:04-05

I have a huge (approx. 1.8gb) JSON file, the data of which I aim to use in an Express app. Loading the JSON file itself is infeasible as Node limits imports to 512mb. I am new to MongoDB (and databases in general) and thus have avoided using them so far, however, this issue appears as though it must be solved using a database.

I am wondering if there is a method by which I can convert my JSON file (which includes data nested up to 5 levels) into a MongoDB document that I can query from my server using Mongoose.

CodePudding user response:

I managed to resolve this issue through further searching. After converting the largest object into an array (creating an array of 2000 smaller objects that were under the 16mb limit hard coded in MongoDB), I used the mongoimport command to convert the JSON into documents.

mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file JSON_FILE --jsonArray
  • Related