# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://avbravo-2.gitbook.io/jmoordb/capitulo-8/introduccion-cap5/importar-un-json-a-mongodb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
