# Migrar desde un archivo sql a mongodb

* **Instalar al editor glogg**

Permite abrir archivos de gran tamaño

sudo apt-get install glogg

* Abrir con el editor glogg el archivo .sql

![](/files/-Lc1WuuUeo-l_lTaTJ7b)

* Copiar el texto en el conversor online

<https://www.csvjson.com/sql2json>

![](/files/-Lc1WuuWaaaMRiVKIwNU)

Pegar el texto desde el create table hasta los insert.

Presionar el botòn Convert

Dar clic en Download o lo copiamos .

![](/files/-Lc1WuuYqs_qA8KWCTeY)

El contenido del archivo convertido

```
{
  "ESTADOS_CIVILES": [
    {
      "ID_ESTADO_CIVIL": "1",
      "DESCRIPCION": "CASADO"
    },
    {
      "ID_ESTADO_CIVIL": "2",
      "DESCRIPCION": "SOLTERO"
    },
    {
      "ID_ESTADO_CIVIL": "3",
      "DESCRIPCION": "DIVORCIADO"
    },
    {
      "ID_ESTADO_CIVIL": "4",
      "DESCRIPCION": "UNIDO"
    },
    {
      "ID_ESTADO_CIVIL": "5",
      "DESCRIPCION": "VIUDO"
    }
  ]
}
```

Procedemss a quitarle esta seccion:

```
{
  "ESTADOS_CIVILES":
```

y la llave final

```
}
```

Quedaría de la siguiente manera

```
[
    {
      "ID_ESTADO_CIVIL": "1",
      "DESCRIPCION": "CASADO"
    },
    {
      "ID_ESTADO_CIVIL": "2",
      "DESCRIPCION": "SOLTERO"
    },
    {
      "ID_ESTADO_CIVIL": "3",
      "DESCRIPCION": "DIVORCIADO"
    },
    {
      "ID_ESTADO_CIVIL": "4",
      "DESCRIPCION": "UNIDO"
    },
    {
      "ID_ESTADO_CIVIL": "5",
      "DESCRIPCION": "VIUDO"
    }
  ]
```

* **Cambiar los nombres de atributos de mayúsculas a minúsculas**

Desde un editor cualquiera. usamos el Find and Replace y buscamos el texto original y lo reemplazamos por el texto en minúsculas. En este ejemplo simplificamos un poco el nombre del atributo. Hacemos lo mismo para cada atributo.

![](/files/-Lc1Wuu_HZkduN80v0x8)

Para el atributo descripciòn

![](/files/-Lc1WuubD0Bns3za5apJ)

El archivo quedaria

```
[
{
"idestadocivil": "1",
"descripcion": "CASADO"
},
{
"idestadocivil": "2",
"descripcion": "SOLTERO"
},
{
"idestadocivil": "3",
"descripcion": "DIVORCIADO"
},
{
"idestadocivil": "4",
"descripcion": "UNIDO"
},
{
"idestadocivil": "5",
"descripcion": "VIUDO"
}
]
```

**Ahora ejecutamos el comando import**

```
mongoimport --db clinica --collection estadocivil --type json --file estadocivil.json --jsonArray
```

![](/files/-Lc1Wuud2gKJtJxPdHo-)

Ejecuamos mongo

![](/files/-Lc1WuufcZnnvTRA1H7z)


---

# 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/migrar-desde-un-archivo-sql-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.
