Skip to main content

Create documents

ArangoDB's official AQL docs for INSERT can be found here

tip

We are going to creating documents to cover the basics of create.

  • To avoid polluting the travel dataset we created a scratch collection here
  • We will be using the ArangoDB Query Interface to run the queries, see instructions to get to the interface here

Autogenerated keys

  1. Create an empty document using the following AQL query:

    insert {} into scratch return NEW
  2. The AQL query above creates and empty document, ArangoDB auto-generates the key

  3. The return NEW is optional, it returns the document that was created. Note: The keyword NEW needs to be in capital case

  4. You can view the results in either JSON or Table format

    • Table format: "Table format"
    • JSON format: "Table format"
  5. You can also run the AQL query below, the created document will not be returned:

    insert {} into scratch 
  6. You can also create a document with additional attributes/fields (without specifying an _key), ArangoDB auto-generates the key

    insert {'field1': 'foo', 'field2': 'bar'} into scratch return NEW

    "Specify fields"

  7. The following query is analogous to the previous query, quotes are not required 1 on the field names however are required on string values

    insert {field1: 'foo', field2: 'bar'} into scratch return NEW
  8. 1 Unless there are spaces or special characters in the field names
    • The following query will error / fail
      insert {field1: 'foo', field2: bar, field 3: 'baz'} into scratch return NEW
    • The following corrected query will succeed
      insert {field1: 'foo', field2: 'bar', 'field 3': 'baz'} into scratch return NEW

Explicit keys

  1. You can explicitly specify the keys:
    insert {'_key': 'foo-bar', field1': 'foo', 'field2': 'bar'} into scratch return NEW
    "Fields and Key"
 
Help us improve

Anything unclear or buggy in this tutorial? Provide Feedback