I want to make a query about a mongoDB database with a python script that will allow me to modify the query about the schedule. However I am not able to visualize the result:
#!/usr/bin/python
import pymongo
import datetime
import pprint
from pymongo import MongoClient
client = MongoClient('mongodb://swiper_read:...')
db = MongoClient().aggregation_example
# // Pipeline
pipeline =[
{ "subscribedFlux": { "$exists": "true" } }
]
a = pprint.pprint(list(db.things.aggregate(pipeline)))
print a
But the terminal tells me:
:~$ python testMongoDB.py
/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/common.py:555: UserWarning: Unknown option 3t.databases
warnings.warn(str(exc))
/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/common.py:555: UserWarning: Unknown option 3t.uriVersion
warnings.warn(str(exc))
/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/common.py:555: UserWarning: Unknown option 3t.connectionMode
warnings.warn(str(exc))
/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/common.py:555: UserWarning: Unknown option 3t.connection.name
warnings.warn(str(exc))
Traceback (most recent call last):
File "testMongoDB.py", line 47, in <module>
a = pprint.pprint(list(db.multifeeds.aggregate(pipeline))) # fue lo que utilisaba antes
File "/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/collection.py", line 1845, in aggregate
with self._socket_for_reads() as (sock_info, slave_ok):
File "/home/antoine/anaconda2/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/mongo_client.py", line 859, in _socket_for_reads
with self._get_socket(read_preference) as sock_info:
File "/home/antoine/anaconda2/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/mongo_client.py", line 823, in _get_socket
server = self._get_topology().select_server(selector)
File "/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/topology.py", line 214, in select_server
address))
File "/home/antoine/anaconda2/lib/python2.7/site-packages/pymongo/topology.py", line 189, in select_servers
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
There is an information about where this pymongo is:
$ pip install pymongo
Requirement already satisfied: pymongo in ./anaconda2/lib/python2.7/site-packages
I do not have mongod.conf
mongodb.conf
in etc
Update 24/5/2017
I installed mongodb-server:
sudo apt install mongodb-server
And today I have an error
exception: Unrecognized pipeline stage name: '$count'
I think, according to ares, which gives an answer about SO in English I do not have the latest version of mongodb but it also allows me to do:
pipeline =[
{
"$match": {
"subscribedFlux": { "$exists": "true" }
}
},
{
"$group": {
"_id" : "null",
"count" : {"$sum" : "1"}
}
}
]
and get a result that is not true according to:
[]
None