Tapas Chand wrote:I think it can be done by keeping ids of Agent in Property and ids of Property in Agent as array.
I think this is probably the simplest solution here.
MongoDB does not support joins or foreign key constraints, but there's nothing to stop you running 2 single-collection queries instead of one join query. If you want to know which properties Bob is handling, fetch Bob's details, then take his list of property IDs and fetch the corresponding properties. If you want to know which agents are handling 23 Acacia Gardens, fetch the property details, then take its list of agent IDs and fetch the agent details.
Updates will be inconsistent (briefly) because you will have to update documents in both collections e.g when Bob gets a new property to handle, but that's part of the cost of using MongoDB: no transactions. There is a risk that over time the agent and property collections could become inconsistent e.g. because of failures during one of the updates. You might want to think about how to control this e.g. run queries to check updates succeeded, but that will depend on your needs.
EDIT:
You can also use the
Write Concern to check if your individual update operations succeeded (e.g. when you update both of them at the same time), so that you can be more confident that your Agents and Properties collections are consistent.