4

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?

Jay
  • 34,438
  • 18
  • 52
  • 81
  • Why are you using salesperson as a partition key when you want to be able to share data? Why not have partitions of 'invoices' and 'customers' and 'salespeople' since all of those resources are shared. I would think you would only have a partition 'locked' to one user if it's just their data -e.g. their preferences or their favorite iTunes tracks. – Jay Jul 22 '20 at 18:13
  • @jay I want to download to the mobile device only the invoices of the salesman that use the current device. Both to save sync performance, and to not share data of other salesmen with the exclusion of invoices that the other salesmen created to the current salesman's customers. Hope this make it clearer. – user13973636 Jul 23 '20 at 05:29
  • 1
    further to this it actually suggests in the documentation an approach along these lines so i think this is a valid question but I would suggest not duplicating the data as this will get very unwieldy very quickly: https://docs.mongodb.com/realm/sync/partitioning/ Maybe an option could be multiple realm sync apps partitioned by different fields (assuming this is sync) that way you could have a realm for the salesman and a realm for the store – LawrenceMouarkach Oct 21 '20 at 09:09

1 Answers1

1

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.