Jeel Prajapati
Jeel Prajapati

Reputation: 41

MongoDB + Laravel fetch value if field exists in array otherwise fetch value from another field in array

I am working with laravel 5.3 and jenssegers-mongodb.

I have following document in MongoDB :

{
    "_id" : ObjectId("590fgfhddfgdfgdfgdg"),
    "name" : {
        "en" : "Meeting",
        "gu" : "બેઠક"
    },
},
{
    "_id" : ObjectId("590fgfhddfgdfgdfgdg"),
    "name" : {
        "en" : "All",
    },
}

I would like to fetch value if (name.gu) is exist, otherwise fetch from (name.en).

Is it possible ?

Upvotes: 3

Views: 759

Answers (1)

Amit Shah
Amit Shah

Reputation: 8199

Solution:

I was able to achieve his using ->whereNull(<column>)

for me check if deleted column do not exists ->whereNull('deleted')

Upvotes: 0

Related Questions