【发布时间】:2020-10-02 05:55:40
【问题描述】:
假设我有这个结构:
{
"_id": "Henry IV",
"acts": [
{
"_id": "ACT I",
"scenes": [
{
"_id": "SCENE I. London. The palace.",
"speeches": [
{
"_id": 1,
"speaker": "KING HENRY IV",
"lines": [
{
"_id": "1.1.1",
"text": "So shaken as we are, so wan with care,"
},
{
"_id": "1.1.2",
"text": "Find we a time for frighted peace to pant,"
},
{
"_id": "1.1.3",
"text": "And breathe short-winded accents of new broils"
}]
},
{
"_id": 2,
"speaker": "WESTMORELAND",
"lines": [
{
"_id": "1.1.34",
"text": "My liege, this haste was hot in question,"
},
{
"_id": "1.1.35",
"text": "And many limits of the charge set down"
}]
}]
}]
}]
}
¿如何获得按“行”数排序的结果并具有父节点属性?理想的结果应该是这样的:
{'play': 'Henry IV', 'act': 'ACT I', 'scene': 'SCENE I. London. The palace.', 'speech', '1', 'speaker': 'KING HENRY IV', 'line_count': 3}
{'play': 'Henry IV', 'act': 'ACT I', 'scene': 'SCENE I. London. The palace.', 'speech', '2', 'speaker': 'WESTMORELAND', 'line_count': 2}
【问题讨论】:
标签: mongodb aggregation-framework pymongo