I have a users collection in my mongoDB. Now I want to update favorites array only if its size is less than 50.
"_id": 'mongo_id',
"name": "test user",
"email": "test_4@gmail.com",
"full_name": "",
"first_name": "",
"last_name": "",
"mobile_number": "",
"email_id": "test_4@gmail.com",
"profile_photo": "",
"roles": [],
"favorites": [
{ obj1 }, { obj2 }, { obj3 }, { obj4 },
],
}```
Currently I'm doing it crude way.
Getting all the favorites and checking the size and then pushing the new object into it.
Is there any better approach using mongodb query operators ?
I want to check the size < 50 and then update array in single db call.