How to make a query time counter in MongoDB database using Pymongo?

I am trying to query my MongoDB database using a python script using a counter in a time range. I know there are some differences in translation, like adding "around keywords". But I think I don't know all the rules required to make fom python requests like this.

#! /usr/bin/python

import pymongo
import datetime
import pprint
import dateutil.parser

from pymongo import MongoClient


client = MongoClient('mongodb://HIDDEN')

dateStr="2017-05-22T00:00:00.780+0000"
myDateTime =dateutil.parser.parse(dateStr)

db = client['swiper']
cursor = db.multifeeds.aggregate(
    [
        {"$match": { "action": 2, "$and": [ { "date": { "$gte": myDateTime, "$lte": myDateTime } } ] }},
        {"$unwind": {"path" : "$pagesSeen"}},
        {"$match": {"pageSwiped": "SMART"}},
        {"$count": "count"},
    ]
)

for document in cursor:
    print (document)

      

In 3T studio I have no problem getting the results:

enter image description here

But I get nothing on the terminal, as always when it is unhappy with my 3T / MongoDB queries ...

The desired output is an integer:

Out[22]: 
       125

      

Do you have any ideas?

I called myself from: http://api.mongodb.com/python/current/tutorial.html#querying-by-objectid

In fact, I would love to use a parameter d

for a date or multiple for a day, month, year.

+3


source to share





All Articles