> For the complete documentation index, see [llms.txt](https://avbravo-2.gitbook.io/jee7/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/jee7/capitulo-1-ejb-mongodb/dos/mongodb.md).

# Instalar MongoDB

MongoDB es una base de datos NoSQL, que se basa en el almacenamiento de documentos en una colección.

Sitio Oficial:

[http://www. mongodb.com](http://www./%20mongodb.com)

### Instalar MongoDB en Ubuntu

**Descargarlo desde**

<https://www.mongodb.org/downloads>

**Descomprimir el archivo y renombrar la carpeta como mongodb**

```
  tar xzvf mongodb-linux-x86_64-ubuntu1604-3.4.2.tgz
```

**renombrar**

```
mv mongodb-linux-x86\_64-ubuntu1604-3.4.2 mongodb
```

**Copiarlo la ruta /home/avbravo/mongodb**

&#x20;**Agregarlo al path en /etc/profile**

```
  sudo gedit /etc/profile

  export PATH=$PATH:/home/avbravo/mongodb
```

**Guardamos el archivo.**

**Desde la consola ejecutamos**

```
     export PATH=$PATH:/home/avbravo/mongodb
```

**Crear el directorio data**

```
    sudo mkdir -p /data/db
```

**Darle permisos de escritura a la carpeta**

```
    sudo chmod 777 /data/db
```

**Ejecutarlo**

```
   cd mongodb/bin

  ./mongod
```

y otra con interfaz web

```
 ./mongod --rest
```

## **Comandos**

| Comando                                                       | Definición                                    |
| ------------------------------------------------------------- | --------------------------------------------- |
| use myappdb                                                   | Crea la base de datos                         |
| show dbs                                                      | Muestra las bases de datos                    |
| db.createCollection("planetas")                               | Crea la colección de planetas                 |
| db.planetas.insert({"idplaneta":"tierra","planeta":"Tierra"}) | Inserta un documento en la colección planetas |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/jee7/capitulo-1-ejb-mongodb/dos/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.
