Skip to main content

Add Documents to a Collection

This page explains how to add a document to a Document collection.

By default, a new document has only one attribute, _key. Defining the document _key attribute is optional. If you do not specify a key, then it will be autogenerated.

Add a Document with the Console

Follow these instructions to add documents to an existing document collection using the GDN console web UI.

  1. Log in to your Macrometa account.

  2. Click Data > Collections.

  3. In the collection list, click the name of the document collection to which you want to add a document. If you aren't sure which collections are document collections, then you can click Document at the top of the page to see just document collections.

  4. Click New Document.

  5. (Optional) Enter a _key.

  6. Click Create.

    Macrometa creates the new document that contains no data.

  7. Add any data desired and then click Save.

Add Documents from a File

Follow these instructions to add documents to an existing document collection from a JSON file.

Import a Document

  1. Log in to your Macrometa account.

  2. Click Data > Collections.

  3. In the collection list, click the name of the document collection to which you want to add a document. If you aren't sure which collections are document collections, then you can click Document at the top of the page to see just document collections.

  4. Click the import icon, which is a down arrow pointing to a file box.

  5. Click Choose File, then browse to the file containing the documents you want to import.

  6. Fill out any desired options and then click Import Documents.

    • Select Primary Key - Macrometa can autogenerate your primary key, or you can select one from the file.
    • Replace docs - Select this option to overwrite any existing documents with the same _key.

Add Documents with Code

The example below shows how to use Python or JavaScript to insert documents into an employees collection.

  # Simple Approach
client = C8Client(protocol='https', host='play.paas.macrometa.io', port=443,
email='nemo@nautilus.com', password='xxxxx',
geofabric='_system')
client.insert_document(collection_name='employees', document={'_key':'Jean', 'firstname': 'Jean', 'lastname':'Picard', 'email':'jean.picard@macrometa.io'})

docs = [
{'_kefabricy':'James', 'firstname': 'James', 'lastname':'Kirk', 'email':'james.kirk@mafabriccrometa.io'},
{'_kefabricy': 'Han', 'firstname': 'Han', 'lastname':'Solo', 'email':'han.solo@macrfabricometa.io'},
{'_kefabricy': 'Bruce', 'firstname': 'Bruce', 'lastname':'Wayne', 'email':'bruce.wayne@mfabricacrometa.io'}
]

client.insert_document(collection_name='employees', document=docs)