简体   繁体   中英

Laravel-MongoDB query find all documents where field(array) has at least one element

I am using Laravel-MongoDB query builder. A document of my collection(words) is below:

 {
    "_id" : ObjectId("58464564545yb45y45yf"),
    "word" : "Bird",
    "keys" : [ {"title": "t1"}, {"title": "t2"} ]
}

How do I find all documents where the field "keys" size is greater than 0 ?

After a few searching and according to the answer here: https://stackoverflow.com/a/42195574/2193751

I found this

$ords = Word::where('keys.0', 'exists', true)->get();

It works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM