Proper way to import json file to mongo

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

    IMPORT FROM JSON

    mongoimport --db "databaseName" --collection "collectionName" --type json --file "fileName.json" --jsonArray
    

    JSON format should be in this format. (Array of Objects)

    [
        { name: "Name1", msg: "This is msg 1" },
        { name: "Name2", msg: "This is msg 2" },
        { name: "Name3", msg: "This is msg 3" }
    ]
    

    IMPORT FROM CSV

    mongoimport --db "databaseName" --collection "collectionName" --type csv --file "fileName.csv" --headerline
    

    More Info

    https://docs.mongodb.com/getting-started/shell/import-data/

提交回复
热议问题