问题
I am trying to query a very tangled collection.
The schema:
{'tags': {'variables': [{'value': '3x9', 'var_name': 's'},
{'value': '12:00AM', 'var_name': 'x'},
{'value': 'goog', 'var_name': 'y'}]},
'url': 'https://www.google.com'}]
The Query:
res = mycol.aggregate([{"$unwind":"$tags"}
,{'$match': {'tags.tag.name':'A A', 'aR': 98765}}
,{'$project': {'url': 1, 'tags.vars': 1, '_id': 0}},])
res = list(res)
for x in res:
print(res)
The Result:
{'tags': {'variables': [{'value': '3x9', 'var_name': 's'},
{'value': '12:00AM', 'var_name': 'x'},
{'value': 'goog', 'var_name': 'y'}]},
'url': 'https://www.google.com'}]
The Expected Result:
[{'value': '3x9', 'var_name': 's'},
{'value': '12:00AM', 'var_name': 'x'},
{'value': 'goog', 'var_name': 'y'},
'url': 'https://www.google.com']
I will use it as a HttpResponse
and use it as a JSON
object.
Please Help!
回答1:
Can you just say res['tags']['variables'] instead of res = list(res)?
来源:https://stackoverflow.com/questions/52829141/query-tangled-array-in-pymongo