【发布时间】:2014-11-10 03:44:40
【问题描述】:
考虑以下集合,
{
"_id": ObjectId("545c535e75de3e630c8b4567"),
"tables" : [
{
"_id" : ObjectId("54584f5975de3e040fe97319"),
"title" : "001",
},
{
"_id" : ObjectId("54584fb175de3e1c0fe97319"),
"title" : "002",
}
]
}
我需要从其中 tables.title = "001" 的集合中检索数据。我使用了laravel框架。我尝试了以下代码,但没有正常工作。如果有人有解决此问题的想法,请帮助我。
DB::connection($this->connection)->collection($this->collection)->where('tables','elemMatch',array('title'=>"001"))->get();
DB::connection($this->connection)->collection($this->collection)->where('tables.title',"001")->get();
DB::connection($this->connection)->collection($this->collection)->where('tables.$.title',"001")->get();
【问题讨论】:
-
我不了解 laravel 框架,但是 mongo 聚合查询可以解决您的问题。
标签: php mongodb laravel mongodb-query aggregation-framework