Please bare with me for I just started working with mongoDB. Here’s my sample scenario. I have 3 collections: Dogs, Cats and PetsInventory and a pet data that I need to insert in PetsInventory collection.
Dogs Collection:
{
"total": 3,
"breeds": [
{ "_id": d1, "name": "labrador" },
{ "_id": d2, "name": "dalmatian" },
{ "_id": d3, "name": "husky"}
]
}
Cats Collection:
{
"total": 3,
"breeds": [
{ "_id": c1, "name": "persian" },
{ "_id": c2, "name": "ragdoll" },
{ "_id": c3, "name": "siamese" }
]
}
PetsInventory Collection:
{
"total": 0,
"items": []
}
And a pet data to be inserted in PetsInventory Collection:
{
"_id": p1
"petOriginId" : c1
"description": "male labrador"
}
I need to save the pet data to PetsInventory collection but before that, i need to find out if the value of its petOriginId field is existing in either Dogs collection or Cats collection otherwise it wont be inserted. Thank you in advance!