Onca
Onca

Reputation: 1135

PyMongo query field of documents

In my DynamoDB every document has several fields, one of the fields is a document called "engines" that holds several documents (all the engines) that hold several fields, as the picture shows below:

enter image description here

I would like to get all the couples of (engine,definitions) that their definition date is greater than a specific date.

I tried:

cursor=collection.find(
                     {'engines': { "$elemMatch" : 
                                  { "definitions" : 
                                   {'$gt': startdate} } } }
                                    ,{'engines':{'$elemMatch':1}},{'engines':{'$elemMatch':{'definitions':1}}}  )

but I get: TypeError: skip must be an instance of int

Can someone help with the query?

Upvotes: 1

Views: 322

Answers (1)

alecxe
alecxe

Reputation: 473773

You've mixed up the closing } and ended up passing {'engines':{'$elemMatch':{'definitions':1}}} as a skip argument value.

I think you meant:

cursor = collection.find(
    {
        'engines': {
            "$elemMatch": {
                "definitions": {
                    '$gt': startdate
                }
            }
        }
    },
    {
        'engines': {
            '$elemMatch': {
                'definitions': 1
            }
        }
    }
)

Upvotes: 1

Related Questions