2014-04-29 3 views
2

PyMongo API에서 복잡한 쿼리를 순서대로 수행하는 것이 가능한지 궁금합니다. 데이터베이스가 있는데 데이터를 검색하려고합니다. 데이터베이스 기능은 {id, username, ...}이고, ID는 {uid, timestamp}입니다. 특정 uid을 확인하는 쿼리를 수행하고 싶습니다. 나는 내 쿼리를 수행 할 수 있습니다 timestamp 추가하는 경우PyMongo - 하나의 중첩 된 필드로 일치

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 

편집

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

: 내가 좋아하는 뭔가를 시도했습니다. timestamp을 추가하지 않고 어떻게 그렇게 할 수 있습니까?

답변

1

당신은 부모 필드 이름과 중첩 된 필드 이름 사이에 점을 추가하여 중첩 된 필드에 액세스 할 수 있습니다 :

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

이 해결책이다

관련 문제