This is how my Mongoose db looks like
_id: ObjectId("5c7d6b0b54795c02a6a5cb16")
people:[
{
_id: ObjectId('7c7d6b0b54795c02a6aa878')
name: John
bizs:[
{name:"Shop A"},
{name:"Shop B"}
]
},
{
_id: ObjectId('7c7d6b0b54795c02638b9cd')
name: Mary
bizs:[
{name:"Shop X"}
]
}
]
If I add a person who is already in the database (say for example John) with his business, I need the business to append itself in the bizs array. Eg Shop A,ShopB, Shop C.
But if I add another person who is not in the database (like how I have added Mary) I need it to create a whole new object in the people array.
I have tried doing this with upsert but it does'nt give me what I want.
How do I get something like this?