Laravel-MongoDB 查询查找字段(数组)至少有一个元素的所有文档
Laravel-MongoDB query find all documents where field(array) has at least one element
我正在使用 Laravel-MongoDB 查询生成器。我的 collection(words) 文档如下:
{
"_id" : ObjectId("58464564545yb45y45yf"),
"word" : "Bird",
"keys" : [ {"title": "t1"}, {"title": "t2"} ]
}
如何找到字段 "keys" 大小大于 0 的所有文档?
经过一番搜索,根据这里的回答:
我找到了这个
$ords = Word::where('keys.0', 'exists', true)->get();
对我有用。
我正在使用 Laravel-MongoDB 查询生成器。我的 collection(words) 文档如下:
{
"_id" : ObjectId("58464564545yb45y45yf"),
"word" : "Bird",
"keys" : [ {"title": "t1"}, {"title": "t2"} ]
}
如何找到字段 "keys" 大小大于 0 的所有文档?
经过一番搜索,根据这里的回答:
我找到了这个
$ords = Word::where('keys.0', 'exists', true)->get();
对我有用。