0

我在 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"
            }
]
       }

    }
4

2 回答 2

2
$crickets = DB::collection('games')->where('Personal_info.hobbies.games', 'cricket')->get();

像这样的东西应该工作

于 2017-10-27T09:07:46.533 回答
2

您可以whereRaw结合使用方法elemMatch

DB::collection('users')->where(
    'Personal_info.hobbies',
    'elemMatch',
    [ 'games' => 'cricket' ]
)->get()
于 2017-10-27T09:09:01.263 回答