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
python mongodb


source to share


No one has answered this question yet

See similar questions:

0
pymongo: name 'ISODate' is undefined

or similar:

2601
How can I make a time delay in Python?
2568
How to find the current time in Python
1299
How can I query MongoDB with "how"?
1086
How to connect to MySQL database in Python?
825
How to delete MongoDB database from command line?
459
When to use MongoDB or other document-oriented systems?
453
How do you rename MongoDB database?
405
Delete everything in MongoDB database
2
MongoDb pymongo how to increase the number of documents
0
about pipeline aggregation mongodb operator ($ slice (aggregation))



All Articles
Loading...
X
Show
Funny
Dev
Pics