如何查找匹配嵌套键 laravel mongodb jenssegers 的记录
How to find record matching the nested key laravel mongodb jenssegers
我在 laravel 中使用 jenssegers mongodb 包来查询 mongodb。如何在下面的 json 文档中检索仅匹配游戏作为板球的记录。
{
"_id": ObjectId("53402597d852426020000002"),
"contact": "987654321",
"dob": "01-01-1991",
"gender": "M",
"name": "Tom Benzamin",
"user_name": “tombenzamin”,
“Personal_info”:[
hobbies:{
"games": "cricket",
"favfilms": "lotr",
"favfood": "burger"
}
]
}
}
$crickets = DB::collection('games')->where('Personal_info.hobbies.games', 'cricket')->get();
像这样的东西应该有用
您可以使用 whereRaw
method combined with elemMatch
:
DB::collection('users')->where(
'Personal_info.hobbies',
'elemMatch',
[ 'games' => 'cricket' ]
)->get()
我在 laravel 中使用 jenssegers mongodb 包来查询 mongodb。如何在下面的 json 文档中检索仅匹配游戏作为板球的记录。
{
"_id": ObjectId("53402597d852426020000002"),
"contact": "987654321",
"dob": "01-01-1991",
"gender": "M",
"name": "Tom Benzamin",
"user_name": “tombenzamin”,
“Personal_info”:[
hobbies:{
"games": "cricket",
"favfilms": "lotr",
"favfood": "burger"
}
]
}
}
$crickets = DB::collection('games')->where('Personal_info.hobbies.games', 'cricket')->get();
像这样的东西应该有用
您可以使用 whereRaw
method combined with elemMatch
:
DB::collection('users')->where(
'Personal_info.hobbies',
'elemMatch',
[ 'games' => 'cricket' ]
)->get()