> For the complete documentation index, see [llms.txt](https://avbravo-2.gitbook.io/jmoordb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://avbravo-2.gitbook.io/jmoordb/capitulo-8/introduccion-cap5/importar-un-json-a-mongodb.md).

# Importar un json a MongoDB

Ejecutar

```
mongoimport --db <db-name> --collection <coll-name> --type json --file nombrearchivo.json
--jsonArray
```

## Ejemplo:

Importar un archivo json a una coleccion en mongodb.

![](https://1490144122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6bBVlJX-GjApa1%2F-Lc1WhtDA-TTmZ6My9OJ%2F-Lc1WuCwttM1YGky5ws8%2Fauto2.png?generation=1554820614733181\&alt=media)

Nota: si queremos importar json con userinfo

debemos agregar por ejemplo para panama

```
{"pais":"Panama", "idpais":"PA","userInfo" : [{    "iduserinfo" : "a94b155f-9b87-4afc-a484-2ae752d01de0",      "username" : "avbravo",      "datetime" : { "$date" : 1509894567491 },      "description" : "create"    }]},
```

```
```

Bajar el archivo desde

<https://www.dropbox.com/s/y3098bxlbo8j7on/countries.json?dl=0>

Lo copiamos en /mongodb/bin

![](https://1490144122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6bBVlJX-GjApa1%2F-Lc1WhtDA-TTmZ6My9OJ%2F-Lc1WuCy-g9XMZjp-nmG%2Fcountries.png?generation=1554820610851282\&alt=media)

**Ejecutar**

./mongoimport --db **spard** --collection **pais** --type json --file **countries.json** --jsonArray

Listado de paises en Json

![](https://1490144122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6bBVlJX-GjApa1%2F-Lc1WhtDA-TTmZ6My9OJ%2F-Lc1WuD-1OGpUF-OyJqd%2Ffind.png?generation=1554820615586370\&alt=media)
