Proper way to import json file to mongo

前端 未结 4 846
半阙折子戏
半阙折子戏 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:40

    There is a parameter --jsonArray:

    Accept import of data expressed with multiple MongoDB document within a single JSON array

    Using this option you can feed it an array, so you only need to strip the outer object syntax i.e. everything at the beginning until and including "shops" :, and the } at the end.

    Myself I use a little tool called jq that can extract the array from command line:

    ./jq '.shops' shops.json
    

提交回复
热议问题