现在我有这样的设计:
{
"_id": MongoID,
"name": "Organization 1",
"url": "http://url.url",
people: [] // 20,000 max
},
{
"_id": MongoID,
"name": "Organization 1",
"url": "http://url.url",
people: [] // a different set of 20,000 max
},
{
"_id": MongoID,
"name": "Organization 2",
"url": "http://url.url",
people: [] // 20,000 max
}
这种拆分是为了解决16MB文档大小限制。我想汇总结果以形成以下结果:
{
"_id": MongoID,
"name": "Organization 1",
"url": "http://url.url",
people: [] // combined 40,000 max people
},
{
"_id": MongoID,
"name": "Organization 2",
"url": "http://url.url",
people: [] // 20,000 max
}
我根据people子文档中的一些字段进行查询。这是我目前没有返回结果的群组聚合。当我没有拆分文件时,这很有效。现在它没有。
$search_column_query = array(array("people.search_columns.surname" => "Smith")); // example
$documents_with_results = $db->organization_data->aggregate(array(
array( '$match' => $search_column_query),
array( '$unwind' => '$people' ),
array( '$match' => $search_column_query),
array( '$group' => array(
'_id' => '$_id',
'name' => array( '$first' => '$name' ),
'url' => array( '$first' => '$url' ),
'people' => array( '$push' => '$people' )
))
));
目标是将所有拆分文档合并到一个文档中,并附带一个组合的子文档列表。
感谢您的帮助!