import a mongodb tuple

0
Hello, I'm importing a collection of mongodb documents, I'm importing from a csv file, I'm having trouble importing key pairs: value, mongodb is recognizing everything as string, example: I want the document to be saved on import.

"coordinates" : {
        "latitude" : -9.646375,
        "longitude" : -35.728146
    },

But you're being saved like this:

"coordinates" : "{\"latitude\" :-9.739.990.639.836.790, \"longitude\" : -3.664.870.887.994.760}"
}

The csv file is with the coordinates field so

coordinates
{"latitude" :-9.262.132.106.882.630, "longitude" : -3.793.454.647.064.200}

I would like help so that I can import the document and the bank recognizes this dictionary as it really is, not as a string.

Thank you for your help!

    
asked by anonymous 23.06.2017 / 18:24

1 answer

1

When you have a csv , the line break represents the value for the previous row key, then:

coordinates
{"latitude" :-9.262.132.106.882.630, "longitude" : -3.793.454.647.064.200}

It means that your "title" would be: coordinates, but its value is all this:

{"latitude" :-9.262.132.106.882.630, "longitude" : -3.793.454.647.064.200}

If you want to import a file directly into the shell, you could import your own .json, for example, that would look right.

We assume:

File content: file.json

{
  "Coordenadas": {
    "Latitude": 1231231,
    "Longitude": 212312312
  }
}

And import into the shell:

mongoimport -d suaBase -c suaCollection --type json --file D:\file.json

And the final content in the base:

{
    "_id" : ObjectId("59524d366f8cb1943dc17220"),
    "Coordenadas" : {
        "Latitude" : 1231231,
        "Longitude" : 212312312
    }
}
    
27.06.2017 / 14:25