Multiple partitions in MongoDB Realm

Viewed 829

Trying to model a standard Salesforce mobile app on MongoDB Realm.

The obvious partitioning is to use the salesman as my partition key. This way, I can sync all stores and invoices of each salesman in their own partition.

However, salesman can cross each other stores in certain cases. One salesman can see the stores of other salesman, but should not be able to see its previous invoices.

The original salesman need to see the invoices of his stores even if created by the other salesman.

Can I create multiple partitions to the same dataset?

_partitionKey: "salesman_id=1234"
_partitionKey: "store_id=abcdefg"

and get the required data based on the prefix of the partition key.

or

Do I need to duplicate the data for 2 objects?

Object for the salesman with

_partitionKey: "salesman_id=1234"

and object for the store with _partitionKey: "store_id=abcdefg"

or is there other way to solve this?

1 Answers

To my knowledge you can partition a MongoDB collection into multiple partitions. In your case, it would seem that you would want to partition the invoices by store_id and then have a property in the invoice that records the salesman who created the invoice. I assume that a store could have multiple salesmen, so a store would need to contain a list of salesman ids.

Related