Importing json from file into mongodb using mongoimport

后端 未结 3 982
借酒劲吻你
借酒劲吻你 2020-12-12 23:26

I have my json_file.json like this:

[
{
    \"project\": \"project_1\",
    \"coord1\": 2,
    \"coord2\": 10,
    \"status\": \"yes\",
    \"priority\": 7
}         


        
3条回答
  •  半阙折子戏
    2020-12-13 00:04

    Perhaps the following reference from the MongoDB project blog could help you gain insight on how arrays work in Mongo:

    https://blog.mlab.com/2013/04/thinking-about-arrays-in-mongodb/

    I would frame your import otherwise, and either:

    a) import the three different objects separately into the collection as you say, using the --jsonArray flag; or

    b) encapsulate the complete array within a single object, for example in this way:

    {
    "mydata": 
        [
        {
              "project": "project_1",
              ...
              "priority": 7
        }
        ]
    }
    

    HTH.

提交回复
热议问题