How to add my own parameters into pymongo find function

Question:

Im building a python application that allows you to query data from mongoDB based on the start time and end time that the user puts in. I have been able to connect to mongoDB and put data there. I just cant seem to get the query right. I will show only the function in question because I know that connecting to the database isn’t the problem, only the query.

def query_from_to(self, begin, end):
    self.collection.find("$and" : [ { "x" : {"$gte": begin } }, { "x" : {"$lte": end } } ])

Is this even possible?

Asked By: Malcolm Thompson

||

Answers:

Put this format in your function try:

collection.find([
            {
                "$Date" : {
                    "$gte": begin, 
                    "$lte": end  
                } 
            }
        ])
Answered By: Sabir
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.