A document database has no schema to read, so this builds one by looking: the twenty most recent documents, every field they carry, and the types it saw.
await storage.run({ action: "schema", collection: "orders" });
// {
// sampled: 20,
// fields: [
// { field: "_id", types: ["objectId"], seenIn: 20 },
// { field: "amount", types: ["number"], seenIn: 20 },
// { field: "customer", types: ["object"], seenIn: 20 },
// { field: "customer.email", types: ["string"], seenIn: 19 },
// { field: "refundedAt", types: ["date", "null"], seenIn: 4 }
// ]
// }storage.run(action="schema", collection="orders")
# {
# "sampled": 20,
# "fields": [
# {"field": "_id", "types": ["objectId"], "seenIn": 20},
# {"field": "amount", "types": ["number"], "seenIn": 20},
# {"field": "customer", "types": ["object"], "seenIn": 20},
# {"field": "customer.email", "types": ["string"], "seenIn": 19},
# {"field": "refundedAt", "types": ["date", "null"], "seenIn": 4}
# ]
# }Reading it properly
| Signal | Means |
|---|---|
| seenIn equals sampled | Present on every document sampled. |
| seenIn well below sampled | Optional, or newly added. |
| Several types on one field | It is not consistent — handle both, or fix the data. |
| A field absent entirely | Not in the recent twenty. It may still exist on older ones. |
Twenty recent documents is a sample, not a contract
A field that stopped being written a year ago will not appear, and one added yesterday will dominate. It tells you how to query today's data; it does not describe everything in there.
Nesting and size
Nested objects are walked two levels deep, dotted — customer.email — which is exactly how you filter on them. At most 150 fields come back.
await storage.run({ action: "find", collection: "orders",
filter: JSON.stringify({ "customer.email": "a@example.com" }) });import json
storage.run(action="find", collection="orders",
filter=json.dumps({"customer.email": "a@example.com"}))