Skip to main content
A collection corresponds to a Firestore collection in your database. You declare all collections you want to expose when you instantiate FirebaseExpressSdk, by passing a collections object to the constructor.

Declaring collections

Each key in collections is the exact name of a Firestore collection. Each value is a configuration object that must include documentAttributes.
const collections = {
  users: {
    documentAttributes: ["name", "age", "email"],
  },
  products: {
    documentAttributes: ["title", "price", "stock"],
  },
};

const firebaseExpressSdk = new FirebaseExpressSdk({
  app,
  serviceAccountFile,
  collections,
});

documentAttributes

documentAttributes is a required array of field name strings. It defines the schema for documents in that collection. The SDK enforces this schema on all write operations:
OperationEnforcement
POSTAll attributes must be present in the request body.
PUTAll attributes must be present in the request body.
PATCHAt least one attribute must be present in the request body.
If the request body includes keys that are not listed in documentAttributes, the SDK rejects the request with an error response. Extra fields are never silently ignored.
If documentAttributes is missing from any collection entry, the SDK throws an error immediately at startup — before your server begins listening.
The collection name you use as the key in collections must match the Firestore collection name exactly, including case. "Users" and "users" are treated as different collections.