Proper way to import json file to mongo

前端 未结 4 834
半阙折子戏
半阙折子戏 2020-12-08 04:12

I\'ve been trying to use mongo with some data imported, but I\'m not able to use it properly with my document description.

This is an example of the .json I import u

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 04:35

    Docs note that:

    This utility takes a single file that contains 1 JSON/CSV/TSV string per line and inserts it.

    In the structure you are using -assuming the errors on the gist are fixed- you are essentially importing one document with only shops field.

    After breaking the data into separate shop docs, import using something like (shops being the collection name, makes more sense than using example):

    mongoimport -d test -c shops data.json
    

    and then you can query like:

    db.shops.find({"name":x,"categories.type":"shirts"})
    

提交回复
热议问题