1

I have three collections how can i create a model such that if i want to find a auto_mobile_reference_no of a user with adjustor id: "ABA123" how can i do that?

//Company collection
{
    "company_id" : "NUV123",
    "company_name" : "ABC",

}

//Adjustor collection

{  
    "admin" : true,
    "claim_adjustor_id" : "ABA123",

    "company_id" : "NUV123",
    "adjustor_username" : "test",
    "adjustor_password" : "test"
},
{  
    "admin" : true,
    "claim_adjustor_id" : "XYQ324",

    "company_id" : "NUV123",
    "adjustor_username" : "test1",
    "adjustor_password" : "test22"
}

//Image collection

{  
    "claim_adjustor_id" : "ABA123",
    "automobile_reference_no" : "1LNHM83W13Y609413",

    "date_last_predicted" : "03/12/2019"
}
Ravi Shankar Bharti
  • 8,922
  • 5
  • 28
  • 52
rahulpargi
  • 35
  • 6

1 Answers1

0

MongoDB is not designed to do efficient joins across collections. You should look at merging your data (based on access pattern) into a single collections.

If your collections are unsharded, you can however you aggregation framework. You can use combination of $match and $lookup stages to query a foreign collection and join the data with the other. As of version 4.0, $lookup doesn't support sharded collections. So it might not work for you if your dataset is huge.

You can read more here

banarun
  • 2,305
  • 2
  • 23
  • 40