简体   繁体   English

PyMongo-通过一个嵌套字段进行匹配

[英]PyMongo - Match by one nested field

I am wondering how is it possible to perform complex queries in PyMongo API in order. 我想知道如何在PyMongo API中按顺序执行复杂的查询。 I've got a database and I want to retrieve data. 我有一个数据库,我想检索数据。 Database feature are {id, username, ...} , id contains {uid, timestamp} . 数据库功能包括{id, username, ...} ,id包含{uid, timestamp} I want to perform queries checking the specific uid . 我想执行查询以检查特定的uid I've tried something like: 我已经尝试过类似的东西:

db = client.test_database
db = client['trendSetters']
collection = db.test_collection
collection = db["cms_users_features"]
result =  collection.find_one()

for col in collection.find({"_id": {"uid": 702993}}):
    print col

EDIT 编辑

for col in collection.find({"_id": {"uid": 702993, "timestamp":1393554289813 }}):
    print col

If I add timestamp I can perform my query. 如果添加timestamp ,则可以执行查询。 How is it possible to do so, without adding timestamp ? 不添加timestamp怎么办?

You can access the nested field by adding a dot between a parent field name and a nested field name: parent_field.child_field 您可以通过在父字段名称和嵌套字段名称之间添加一个点来访问嵌套字段: parent_field.child_field

This is the solution: 这是解决方案:

for col in collection.find({"_id.uid": 702993}):
    print col

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM