Escribe para buscar…

Document

MongoDB store data as documents.

Esta página todavía no se ha traducido — se muestra en su idioma original:English

Introduction

A document is a data structure composed of field and value pairs. The value of a field can be a simple data type, such as a string or a number, or it can be a more complex data type, such as an array or another document.

Below you have an example of a JSON document that describes the employee Laura:

json
{
    "_id": "laura",
    "firstName": "Laura",
    "lastName": "Codina",
    "email": "laura@acme.com",
    "department": "Finance"
}

Documents in document databases are self-describing, which means they contain both data values and information about what type of data is stored.

Below you have a document from another employee who works in several departments:

json
{
    "_id": "roser",
    "firstName": "Roser",
    "lastName": "Vilalta",
    "email": "roser@acme.com",
    "salary": 70000,
    "department": ["Finance", "Accounting"]
}

This second document has some differences compared to the first example.

In document databases:

  • Documents not only describe themselves, but also their schema is dynamic, which means you don’t need to define it before starting to save data.
  • Fields can differ between different documents in the same database, and you can modify the document structure at will, adding or removing fields as you go.
  • Documents can also be nested, that is, a field of a document can have a value consisting of another document, allowing you to store complex data within a single document entry.
json
{
    "_id": "david",
    "firstName": "David",
    "lastName": "de Mingo",
    "email": "david@acme.com",
    "department": ["Finance", "Accounting"],
    "socialMediaAccounts": [
        {
            "type": "facebook",
            "username": "david_de_mingo"
        },
        {
            "type": "twitter",
            "username": "@ddemingo"
        }
    ]
}

WSL

Start a new Windows Subsystem for Linux (WSL) terminal.

ps
wsl

Estás leyendo una vista previa.

Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.

Iniciar sesión