Persistence with Collections

Persistence with Collections

A Collection is a container of documents and files. It acts as a schemaless document database and a folder of files.

With Collections, you can persist data for your application.

  1. Organize data in collections, indexed with user-specified keys.
  2. Store documents with JSON data (optionally indexed with user-specified keys).
  3. Store files (optionally indexed with user-specified keys).
  4. Tag documents and files with key/value tags, and filter documents and files by these tags.

Numerous Collections currently only support apps that are deployed to Numerous.

Remember to add numerous as a dependency in your project; most likely to your requirements.txt file.

Basic usage

Import the Numerous SDK (opens in a new tab) in your Python code.

Now, you can add code to your app that is similar to the following:

import numerous
 
# Refer to a collection by its key
collection = numerous.collection("my-collection")
 
# Refer to a collection nested inside another collection
nested = collection.collection("nested-collection")
 
# Refer to a document by its key
document = collection.document("my-document")
 
# Read a document's data
data = document.get()
 
# Update a document with new data
data["my-value"] = "new value"
document.set(data)
 
# Loop over documents in a collection
for doc in collection.documents():
    print(doc.key)
    print(doc.get())
 
# Delete a document
document.delete()
 
# Check if a document exists
if document.exists:
    print("document exists")
else:
    print("document does not exist)