Import a embedded json document with compass. Error: "Operation passed in cannot be an Array"

Hi to everyone,
I’m traing to import this simple document that i found at this link . I have created a file .json by coping this code:{ "_id": "joe", "name": "Joe Bookreader", "addresses": [ { "street": "123 Fake Street", "city": "Faketon", "state": "MA", "zip": "12345" }, { "street": "1 Some Other Street", "city": "Boston", "state": "MA", "zip": "12345" } ] }
Than i have imported this file in compass (like the documentation explain at this link), but when i upload the data, this error appear:

Operation passed in cannot be an Array

I don’t understan why. MongoDB should be optimizered for nested documents…
Anyone can help me please?

Hi,

I just tried it in my end.

I created a blank test.json file and I copied the data from the question. I then opened Compass and clicked “ADD DATA” → “Import File” → “BROWSE” → “IMPORT”.

It worked in my end without an error.

Ok, thank you so much @NeNaD , i found the mistake. I have created the file .json with visual studio code with the following structure:

{
   "_id": "joe",
   "name": "Joe Bookreader",
   "addresses": [
                {
                  "street": "123 Fake Street",
                  "city": "Faketon",
                  "state": "MA",
                  "zip": "12345"
                },
                {
                  "street": "1 Some Other Street",
                  "city": "Boston",
                  "state": "MA",
                  "zip": "12345"
                }
              ]
 }

With this type of structure i have the error, but if i create a .json file with Blocknote and the following structure :{ "_id": "joe", "name": "Joe Bookreader", "addresses": [ { "street": "123 Fake Street", "city": "Faketon", "state": "MA", "zip": "12345" }, { "street": "1 Some Other Street", "city": "Boston", "state": "MA", "zip": "12345" } ] } the error disappear.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.