Skip to content
Advertisement

How to add my own parameters into pymongo find function

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?

Advertisement

Answer

Put this format in your function try:

collection.find([
            {
                "$Date" : {
                    "$gte": begin, 
                    "$lte": end  
                } 
            }
        ])
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement