> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ditto.live/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating Documents

> This article provides how-to instructions for creating documents within Ditto.

See [Document Model](/key-concepts/document-model) for more information on documents in Ditto.

## Creating Documents

To insert a document, call the `EXECUTE` API method against the `ditto.store` object and include an `INSERT INTO` query that specifies the document to be inserted.

<Info>
  Embed related data within a single document — typically as a map keyed by ID — for atomic single-document sync. See [Denormalized Documents](/best-practices/conflict-resolution-patterns#denormalized-documents-one-document-atomic-sync) for the recommended pattern, or use a [foreign-key relationship](/key-concepts/document-model#relationships) across collections when sub-entities need their own permission scope or independent access.
</Info>

For example, the following snippet demonstrates how to insert a new document with a single field "color" set to "blue":

<CodeGroup>
  ```swift Swift theme={null}
  await ditto.store.execute(
      query: "INSERT INTO cars DOCUMENTS (:newCar)",
      arguments: ["newCar": ["color": "blue"]]);
  ```

  ```kotlin Kotlin theme={null}
  ditto.store.execute(
      "INSERT INTO cars DOCUMENTS (:newCar)",
      mapOf("newCar" to mapOf("color" to "blue")))
  ```

  ```javascript JS theme={null}
  await ditto.store.execute(
      "INSERT INTO cars DOCUMENTS (:newCar)",
      { newCar: { color: "blue" } }
  );
  ```

  ```typescript TypeScript theme={null}
  interface Car {
    color: string;
  }

  await ditto.store.execute(
      "INSERT INTO cars DOCUMENTS (:newCar)",
      { newCar: { color: "blue" } as Car }
  );
  ```

  ```java Java theme={null}
  import static com.ditto.java.serialization.DittoCborSerializable.buildDictionary;

  ditto.getStore().execute(
      "INSERT INTO cars VALUES (:newCar)",
      buildDictionary()
          .put("newCar", buildDictionary()
              .put("color", "blue")
              .build())
          .build())
  .close(); // DittoQueryResult from execute() MUST always be explicitly closed.
  ```

  ```csharp C# theme={null}
  var args = new Dictionary<string, object>();
  args.Add("newCar", new { color = "blue" });

  await ditto.Store.ExecuteAsync(
      "INSERT INTO cars DOCUMENTS (:newCar)",
      args);
  ```

  ```cpp C++ theme={null}
  std::map<std::string, std::map<std::string, std::string>> args;

  args["newCar"] = {{"color", "blue"}};

  ditto.get_store().execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    args);
  ```

  ```rust Rust theme={null}
  ditto
    .store()
    .execute((
      "INSERT INTO cars DOCUMENTS (:newCar)",
      serde_json::json!({
          "newCar": {
              "color": "blue"
          }
      }),
    )).await?;
  ```

  ```dart Dart theme={null}
  await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: {"newCar": {"color": "blue"}},
  );
  ```

  ```go Go theme={null}
  result, err := dit.Store().Execute(
  	"INSERT INTO cars DOCUMENTS (:newCar)",
  	ditto.QueryArguments{
  		"newCar": ditto.Document{
  			"color": "blue",
  		},
  	},
  )
  if err != nil {
      return err
  }
  defer result.Close()  // cleanup

  ```
</CodeGroup>

If desired, supply a document ID in your creation request; otherwise, Ditto automatically generates and assigns one.

## Inserting Multiple Documents

To efficiently create multiple documents, use the INSERT INTO operation and specify multiple query parameters, as follows:

<CodeGroup>
  ```swift Swift theme={null}
  await ditto.store.execute(
    query: "INSERT INTO cars DOCUMENTS (:doc1), (:doc2)",
    arguments: [
      "doc1": ["color": "blue"],
      "doc2": ["color": "red"]
    ]);
  ```

  ```kotlin Kotlin theme={null}
  ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:doc1), (:doc2)",
    mapOf(
      "doc1" to mapOf("color" to "blue"),
      "doc2" to mapOf("color" to "red"),
      ))
  ```

  ```javascript JS theme={null}
  await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:doc1), (:doc2)",
    {
      doc1: { color: 'blue' },
      doc2: { color: 'red' }
    });
  ```

  ```typescript TypeScript theme={null}
  interface Car {
    color: string;
  }

  await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:doc1), (:doc2)",
    {
      doc1: { color: 'blue' },
      doc2: { color: 'red' }
    });
  ```

  ```java Java theme={null}
  import static com.ditto.java.serialization.DittoCborSerializable.buildDictionary;

  var args = buildDictionary()
      .put("doc1", buildDictionary()
          .put("color", "blue")
          .build())
      .put("doc2", buildDictionary()
          .put("color", "red")
          .build())
      .build();

  ditto.getStore().execute(
      "INSERT INTO cars VALUES (:doc1), (:doc2)",
      args)
  .close(); // DittoQueryResult from execute() MUST always be explicitly closed.
  ```

  ```csharp C# theme={null}
  var args = new Dictionary<string, object>();
  args.Add("doc1", new { color = "blue" });
  args.Add("doc2", new { color = "red" });

  await ditto.Store.ExecuteAsync(
    "INSERT INTO cars DOCUMENTS (:doc1), (:doc2)",
    args);
  ```

  ```cpp C++ theme={null}
  std::map<std::string, std::map<std::string, std::string>> args;
  args["doc1"] = {{"color", "blue"}};
  args["doc2"] = {{"color", "red"}};

  ditto.get_store().execute(
    "INSERT INTO cars DOCUMENTS (:doc1), (:doc2)",
    args);
  ```

  ```rust Rust theme={null}
  ditto
    .store()
    .execute((
      "INSERT INTO cars DOCUMENTS (:doc1), (:doc2)",
      serde_json::json!({
          "doc1": {
              "color": "blue"
          },
          "doc2": {
              "color": "red"
          }
      }),
    )).await?;
  ```

  ```dart Dart theme={null}
  await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:doc1),(:doc2)",
    arguments: {
      "doc1": {"color": 'blue'},
      "doc2": {"color": 'red'},
    },
  );
  ```

  ```go Go theme={null}
  result, err := dit.Store().Execute(
  	"INSERT INTO cars DOCUMENTS (:doc1), (:doc2)",
  	ditto.QueryArguments{
  		"doc1": ditto.Document{
  			"color": "blue",
  		},
  		"doc2": ditto.Document{
  			"color": "red",
  		},
  	},
  )
  if err != nil {
      return err
  }
  defer result.Close()  // cleanup
  ```
</CodeGroup>

## Identifying Documents

Unless manually supplied, Ditto automatically generates and assigns the new document a 128‑bit Universally Unique Identifier (UUID).

The document identifier is represented as `_id` and serves as the primary key for the document.

### Retrieving Document IDs

To access the IDs of the documents affected by the INSERT INTO operation, call the `mutatedDocumentIDs` method on the result object after the insertion like this:

<CodeGroup>
  ```swift Swift theme={null}
  let result = await ditto.store.execute(
    query: "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: [
      newCar: ["color": "blue"]
    ]);

  // "507f191e810c19729de860ea"
  print(result.mutatedDocumentIDs()[0])
  ```

  ```kotlin Kotlin theme={null}
  ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    mapOf("newCar" to mapOf("color" to "blue"))).use { result ->
      // "507f191e810c19729de860ea"
      println(result.mutatedDocumentIds().first())
  }
  ```

  ```javascript JS theme={null}
  const result = await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    { newCar: { color: 'blue' } }
  );

  // "507f191e810c19729de860ea"
  console.log(result.mutatedDocumentIDs()[0].value)
  ```

  ```typescript TypeScript theme={null}
  import { QueryResult } from '@dittolive/ditto';

  interface Car {
    color: string;
  }

  const result: QueryResult = await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    { newCar: { color: 'blue' } as Car }
  );

  // "507f191e810c19729de860ea"
  console.log(result.mutatedDocumentIDs()[0].value);
  ```

  ```java Java theme={null}
  import static com.ditto.java.serialization.DittoCborSerializable.buildDictionary;

  // This try-with-resources block auto-closes the DittoQueryResult.
  try (DittoQueryResult result = ditto.getStore().execute(
    "INSERT INTO cars VALUES (:newCar)",
    buildDictionary()
        .put("newCar", buildDictionary()
            .put("color", "blue")
            .build())
        .build()).toCompletableFuture().join()) {
      // "507f191e810c19729de860ea"
      System.out.println(result.mutatedDocumentIDs().stream().findFirst());
  }
  ```

  ```csharp C# theme={null}
  var args = new Dictionary<string, object>();
  args.Add("newCar", new { color = "blue" });

  using var result = await ditto.Store.ExecuteAsync(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    args);

  // "507f191e810c19729de860ea"
  result.MutatedDocumentIds.ForEach(id => Console.WriteLine(id));
  ```

  ```cpp C++ theme={null}
  std::map<std::string, std::map<std::string, std::string>> args;
  args["newCar"] = {{"color", "blue"}};

  auto result = ditto.get_store().execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    args);

  // "507f191e810c19729de860ea"
  std::cout << result.mutated_document_ids()[0].to_string();
  ```

  ```rust Rust theme={null}
  let result = ditto
    .store()
    .execute((
      "INSERT INTO cars DOCUMENTS (:newCar)",
      serde_json::json!({
          "newCar": {
              "color": "blue"
          }
      }),
    )).await?;

  // "507f191e810c19729de860ea"
  println!("{}", result.mutated_document_ids()[0].to_string())
  ```

  ```dart Dart theme={null}
  final result = await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: {
      "newCar": {"color": 'blue'},
    },
  );

  // "507f191e810c19729de860ea"
  print(result.mutatedDocumentIDs.first);
  ```

  ```go Go theme={null}
  result, err := dit.Store().Execute(
  	"INSERT INTO cars DOCUMENTS (:newCar)",
  	ditto.QueryArguments{
  		"newCar": ditto.Document{"color": "blue"},
  	})
  if err != nil {
  	return err
  }
  defer result.Close() // cleanup

  // "507f191e810c19729de860ea"
  log.Printf("%v", result.MutatedDocumentIDs()[0])
  ```
</CodeGroup>

### Supplying String IDs

When creating a document, you can assign it a custom ID. This custom ID can be generated using a single string value or a combination of two or more string values.

This flexibility in structuring document identifiers allows you to customize document IDs to your specific requirements, use cases, or standard naming conventions.

The following snippet demonstrates a new document assigned the custom ID "123".

<CodeGroup>
  ```swift Swift theme={null}
  let result = await ditto.store.execute(
    query: "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: [
      newCar: ["_id": "123", "color": "blue"]
    ]);

  // "123"
  println(result.mutatedDocumentIDs().first())
  ```

  ```kotlin Kotlin theme={null}
  ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    mapOf("newCar" to mapOf("_id" to "123", "color" to "blue")))
  .use { result ->
      // "123"
      println(result.mutatedDocumentIds().first())
  }
  ```

  ```javascript JS theme={null}
  const result = await ditto.store.execute(
      "INSERT INTO cars DOCUMENTS (:newCar)",
      { newCar: { "_id": "123", color: "blue" } }
  );

  // "123"
  console.log(result.mutatedDocumentIDs()[0].value)
  ```

  ```typescript TypeScript theme={null}
  import { QueryResult } from '@dittolive/ditto';

  interface Car {
    _id: string;
    color: string;
  }

  const result: QueryResult = await ditto.store.execute(
      "INSERT INTO cars DOCUMENTS (:newCar)",
      { newCar: { _id: "123", color: "blue" } as Car }
  );

  // "123"
  console.log(result.mutatedDocumentIDs()[0].value);
  ```

  ```java Java theme={null}
  import static com.ditto.java.serialization.DittoCborSerializable.buildDictionary;

  var newCar = buildDictionary()
      .put("_id", "123")
      .put("color", "blue")
      .build();

  // This try-with-resources block auto-closes the DittoQueryResult
  try (DittoQueryResult result = ditto.getStore().execute(
      "INSERT INTO cars VALUES (:newCar)",
      buildDictionary().put("newCar", newCar).build()
  ).toCompletableFuture().join()) {
      // "123"
      System.out.println(result.mutatedDocumentIDs().stream().findFirst());
  }
  ```

  ```csharp C# theme={null}
  var args = new Dictionary<string, object>();
  args.Add("newCar", new { _id = "123", color = "blue" });

  using var result = await ditto.Store.ExecuteAsync(
    "INSERT INTO your_collection_name DOCUMENTS (:newCar)",
    args);

  // "123"
  result.MutatedDocumentIds.ForEach(id => Console.WriteLine(id));
  ```

  ```cpp C++ theme={null}
  std::map<std::string, std::map<std::string, std::string>> args;
  args["newCar"] = {{"_id", "123"},{"color", "blue"}};

  auto result = ditto.get_store().execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    args);

  // "123"
  std::cout << result.mutated_document_ids()[0].to_string();
  ```

  ```rust Rust theme={null}
  let result = ditto
    .store()
    .execute((
      "INSERT INTO cars DOCUMENTS (:newCar)",
      serde_json::json!({
          "newCar": {
              "_id": "123",
              "color": "blue"
          }
      }),
    )).await?;

  // "123"
  println!("{}", result.mutated_document_ids()[0].to_string())
  ```

  ```dart Dart theme={null}
  final result = await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: {
      "newCar": {"_id":"123","color": 'blue'},
    },
  );

  // "123"
  print(result.mutatedDocumentIDs.first);
  ```

  ```go Go theme={null}
  result, err := dit.Store().Execute(
  	"INSERT INTO cars DOCUMENTS (:newCar)",
  	ditto.QueryArguments{
  		"newCar": ditto.Document{
  			"_id":   "123",
  			"color": "blue",
  		},
  	})
  if err != nil {
      return err
  }
  defer result.Close()  // cleanup

  // "123"
  log.Printf("%v", result.MutatedDocumentIDs()[0])
  ```
</CodeGroup>

Following is the new 123 document that results:

```json theme={null}
{
  "_id": "123",
  "color": "blue"
}
```

### Forming Composite Keys

The following demonstrates combining the `vin` and `make` fields to form a composite key:

<CodeGroup>
  ```swift Swift theme={null}
  let arguments = [
    newCar: [ "_id": [vin: "123", make: "Toyota"], "color": "blue"]
  ];

  let result = await ditto.store.execute(
    query: "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: arguments);

  // "{vin: "123", make: "Toyota"}"
  print(result.mutatedDocumentIDs()[0])
  ```

  ```kotlin Kotlin theme={null}
  val arguments = mapOf(
      "newCar" to mapOf(
          "_id" to mapOf("vin" to "123", "make" to "Toyota"),
          "color" to "blue"
      )
  )
  ditto.store.execute(
      "INSERT INTO cars DOCUMENTS (:newCar)",
      arguments
  ).use { result ->
      println(result.mutatedDocumentIDs()[0])
  }
  ```

  ```javascript JS theme={null}
  const newCar = {
    "_id": {
      vin: "123",
      make: "Toyota"
    },
    color: "blue"
  };

  const result = await ditto.store.execute(`
    INSERT INTO cars DOCUMENTS (:newCar)`,
    { newCar });

  // { vin: "123", make: "Toyota" }
  console.log(result.mutatedDocumentIDs()[0].value)
  ```

  ```typescript TypeScript theme={null}
  import { QueryResult } from '@dittolive/ditto';

  interface CarId {
    vin: string;
    make: string;
  }

  interface Car {
    _id: CarId;
    color: string;
  }

  const newCar: Car = {
    _id: {
      vin: "123",
      make: "Toyota"
    },
    color: "blue"
  };

  const result: QueryResult = await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    { newCar });

  // { vin: "123", make: "Toyota" }
  console.log(result.mutatedDocumentIDs()[0].value);
  ```

  ```java Java theme={null}
  import static com.ditto.java.serialization.DittoCborSerializable.buildDictionary;

  var newCarId = buildDictionary()
      .put("vin", "123")
      .put("make", "Toyota")
      .build();

  var newCar = buildDictionary()
      .put("_id", newCarId)
      .put("color", "blue")
      .build();

  // This try-with-resources block auto-closes the DittoQueryResult
  try (DittoQueryResult result = ditto.getStore().execute(
      "INSERT INTO cars VALUES (:newCar)",
      buildDictionary().put("newCar", newCar).build()
  ).toCompletableFuture().join()) {
      // "{vin: "123", make: "Toyota"}"
      System.out.println(result.mutatedDocumentIDs().stream().findFirst());
  }
  ```

  ```csharp C# theme={null}
  var newId = new { vin: "123", make: "Toyota"};
  var args = new Dictionary<string, object>();
  args.Add("newCar", new { "_id" = newId, color = "blue" });

  using var result = await ditto.Store.ExecuteAsync(
    "INSERT INTO your_collection_name DOCUMENTS (:newCar)",
    args);

  // "{vin: "123", make: "Toyota"}"
  result.MutatedDocumentIds.ForEach(id => Console.WriteLine(
    System.Text.Json.JsonSerializer.Serialize(id))
  );
  ```

  ```cpp C++ theme={null}
  struct CarId {
    std::string vin;
    std::string make;
  };

  struct Car {
    CarId _id;
    std::string color;
  };

  std::map<std::string, Car> args;
  args["newCar"] = {{"123", "Toyota"}, "blue"};

  auto result = ditto.get_store().execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    args);

  // "{vin: "123", make: "Toyota"}"
  std::cout << result.mutated_document_ids()[0].to_string();
  ```

  ```rust Rust theme={null}
  let result = ditto
    .store()
    .execute((
      "INSERT INTO cars DOCUMENTS (:newCar)",
      serde_json::json!({
          "newCar": {
              "_id": {
                "vin": "123",
                "make": "Toyota"
              },
              "color": "blue"
          }
      }),
    )).await?;

  // "{vin: "123", make: "Toyota"}"
  println!("{}", result.mutated_document_ids()[0].to_string())
  ```

  ```dart Dart theme={null}
  final result = await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: {
      "newCar": {
        "_id": {"vin": "123", "make": "Toyota"},
        "color": 'blue',
      },
    },
  );

  // "{vin: "123", make: "Toyota"}"
  print(result.mutatedDocumentIDs.first);
  ```

  ```go Go theme={null}
  result, err := dit.Store().Execute(
  	"INSERT INTO cars DOCUMENTS (:newCar)",
  	ditto.QueryArguments{
  		"newCar": ditto.Document{
  			"_id": map[string]any{
  				"vin":  "123",
  				"make": "Toyota",
  			},
  			"color": "blue",
  		},
  	})
  if err != nil {
  	return err
  }
  defer result.Close()  // cleanup

  // "{vin: "123", make: "Toyota"}"
  log.Printf("%v", result.MutatedDocumentIDs()[0])
  ```
</CodeGroup>

# Creating MAPs

There are two ways to create a MAP structure within a document:

* In an INSERT operation — Create a new document and nest it with this set of fields.
* In an UPDATE operation — If the MAP does not exist, create it. (See [UPDATE](./update))

To represent a highly complex data structure in a MAP, consider embedding it with an additional MAP. Embedding a MAP within a MAP establishes an additional hierarchy.

The decision to use deeply embedded MAPS in a single document or opt for a *flat model* depends on your requirements, relationships between data, and tolerance for certain tradeoffs.

<Info>
  The flat model is a simple, non‑embedded structure in which you spread your data across multiple, separate documents.
</Info>

## Inserting to Create a MAP

<Warning>
  ### Disable Strict Mode

  In 4.11+ and `DQL_STRICT_MODE=false`, collection definitions are no longer required.

  [Read more](/dql/strict-mode)
</Warning>

When inserting a new document in Ditto, you can define a field as a MAP and
include the structure of key-value pairs nested within it — a two-in-one
approach. To do this, first disable strict mode before starting synchronization. [Read more](/dql/strict-mode)

<CodeGroup>
  ```swift Swift theme={null}
  let arguments: [String: Any] = [
    "newCar": [
      "_id": "123",
      "properties": [
        "color": "blue",
        "mileage": 3000
      ]
    }
  ];

  await ditto.store.execute(
    query: "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: arguments);
  ```

  ```kotlin Kotlin theme={null}
  val arguments = mapOf(
    "newCar" to mapOf(
      "_id" to "123",
      "properties" to mapOf(
        "color" to "blue",
        "mileage" to 3000
      )
    )
  )

  ditto.store.execute(
    "INSERT INTO cars  DOCUMENTS (:newCar)",
    arguments)
  ```

  ```javascript JS theme={null}
  const newCar = {
    "_id": "123",
    properties: {
      color: 'blue',
      mileage: 3000
    }
  };

  await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    { newCar }
  );
  ```

  ```typescript TypeScript theme={null}
  interface CarProperties {
    color: string;
    mileage: number;
  }

  interface Car {
    _id: string;
    properties: CarProperties;
  }

  const newCar: Car = {
    _id: "123",
    properties: {
      color: 'blue',
      mileage: 3000
    }
  };

  await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    { newCar }
  );
  ```

  ```java Java theme={null}
  import static com.ditto.java.serialization.DittoCborSerializable.buildDictionary;

  var properties = buildDictionary()
      .put("color", "blue")
      .put("mileage", 3000)
      .build();

  var newCar = buildDictionary()
      .put("_id", "123")
      .put("properties", properties)
      .build();

  ditto.getStore().execute(
      "INSERT INTO cars VALUES (:newCar)",
      buildDictionary().put("newCar", newCar).build())
  .close(); // DittoQueryResult from execute() MUST always be explicitly closed
  ```

  ```csharp C# theme={null}
  var subMap = new {
    color = "blue",
    mileage = 3000
  };

  var insertArgs = new Dictionary<string, object>();
  insertArgs.Add("newCar", new { "_id" = newId, properties = subMap })

  using var result = await ditto.Store.ExecuteAsync(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    insertArgs);
  ```

  ```cpp C++ theme={null}
  struct Properties {
    std::string color;
    int mileage;
  };

  struct Car {
    std::string _id;
    Properties properties;
  };

  std::map<std::string, Car> args;
  args["newCar"] = {"123", {"blue", 3000}};

  ditto.get_store().execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    args);
  ```

  ```rust Rust theme={null}
  #[derive(Serialize)]
  struct Properties {
    color: String,
    mileage: i32
  }

  #[derive(Serialize)]
  struct Car {
    _id: String,
    properties: Properties
  }

  #[derive(Serialize)]
  struct Args {
    newCar: Car
  }

  let args = Args {
    newCar: Car {
      _id: "123".to_string(),
      properties: Properties {
        color: "blue".to_string(),
        mileage: 3000
      }
    }
  };

  ditto.store().execute((
    "INSERT INTO cars DOCUMENTS (:newCar)",
    args,
  )).await?;
  ```

  ```dart Dart theme={null}
  final newCar = {
    "_id": "123",
    "properties": {
      "color": 'blue',
      "mileage": 3000,
    },
  };

  await ditto.store.execute(
    "INSERT INTO cars DOCUMENTS (:newCar)",
    arguments: {"newCar": newCar},
  );
  ```

  ```go Go theme={null}
  result, err := dit.Store().Execute(
  	"INSERT INTO cars DOCUMENTS (:newCar)",
  	ditto.QueryArguments{
  		"newCar": ditto.Document{
  			"_id": "123",
  			"properties": map[string]any{
  				"color":   "blue",
  				"mileage": 3000,
  			},
  		},
  	})
  if err != nil {
      return err
  }
  defer result.Close()  // cleanup
  ```
</CodeGroup>

You can also create MAPs within a document after the fact using an UPDATE
operation.

In the UPDATE approach, you set the structure of key-value pairs and specify the
document ID to update.

For example, this statement creates a MAP structure, adding key-value pair of
"color is red" to the properties MAP for the document with the ID 123 in the
cars collection:

```dql DQl theme={null}
UPDATE cars
   SET properties.color = 'red'
 WHERE _id = '123'
```
