简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM