So I’m trying to structure out my schema_version 1 and I wanted to run it by everyone to let me know if I’m on the right track or way off. I know querying is a big thing so I’ll quickly break down relationships and how the application would be used, then my current schema, and then considerations for a schema_version 2. With that said here’s the app flow:
A User can can add a Business which can have several BusinessLocations which can have many employees and many orders.
An order will have one customer, one recipient, be created by an employee, and have providers.
An employee is a user that has certain role for permissions and belongs to a business location.
Here are my current collections: (Assume all documents for each collection have a “_id” by default)
user: {}
business: {
owner: user_id,
locations: [ businessLocation_id, ... ]
}
businessLocation: {
businessId,
employees: [employee_id, ...]
address: {},
...
}
employee: {
businessLocation_id,
user_id,
role
}
order: {
businessLocation_id,
employee_id,
*providers: [],
customer: {},
recipient: {}
}
*Do I need providers in their own document or can I get away with an embedded array of objects that are only to that order if I know that there is a limit per order and I don’t need to know if the provider is part of other orders?
Indexes - Missing any? Wrong ones?
- employee_orders (from order document)
- business_employees (from employees document)
Links/Refs - Am I missing any? Are any unnecessary?
Thinking ahead, I will eventually want to create flexibility for enterprise; An enterprise (organization) may have many brands which could own many businesses with many locations. But this isn’t v1, just something to keep in mind when I eventually may need to migrate data.
Thank you SO much! I know this is a doozy!