PyMongo is the official Python driver for MongoDB created and maintained by MongoDB, Inc. Please mention the version of PyMongo you're using.
PyMongo is the official Python driver for MongoDB created and maintained by MongoDB, Inc.
Note: Since PyMongo 3 is not backward compatible with PyMongo 2 (refer to the changelog for details), you should specify the version you're using in the body of your question.
I am coming from riak and redis where I never had an issue with this services starting, or to interact.
This is a pervasive problem with mongo and am rather clueless. Restarting does not help.I am new to mongo.
mongo
MongoDB shell version:…
I'm trying to use the sort feature when querying my mongoDB, but it is failing. The same query works in the MongoDB console but not here. Code is as follows:
import pymongo
from pymongo import Connection
connection = Connection()
db =…
I am trying to perform a regex query using PyMongo against a MongoDB server. The document structure is as follows
{
"files": [
"File 1",
"File 2",
"File 3",
"File 4"
],
"rootFolder": "/Location/Of/Files"
}
I want to get all…
With PyMongo, when I try to retrieve objects sorted by their 'number' and 'date' fields like this:
db.test.find({"number": {"$gt": 1}}).sort({"number": 1, "date": -1})
I get this error:
TypeError: if no direction is specified, key_or_list must be…
I have a large amount of data in a collection in mongodb which I need to analyze. How do i import that data to pandas?
I am new to pandas and numpy.
EDIT:
The mongodb collection contains sensor values tagged with date and time. The sensor values are…
I can use the SQL Like Operator using pymongo,
db.test.find({'c':{'$regex':'ttt'}})
But how can I use Not Like Operator?
I tried
db.test.find({'c':{'$not':{'$regex':'ttt'}})
but got error:
OperationFailure: $not cannot have a regex
I need to search an ObjectId with python using pymongo but I always get this error. Any ideas how to search?
import pymongo
from pymongo import MongoClient
from pymongo import ObjectId
gate = collection.find({'_id':…
I am having trouble using json.loads to convert to a dict object and I can't figure out what I'm doing wrong.The exact error I get running this is
ValueError: Expecting property name: line 1 column 2 (char 1)
Here is my code:
from kafka.client…
I am using pymongo to query for all items in a region (actually it is to query for all venues in a region on a map). I used db.command(SON()) before to search in a spherical region, which can return me a dictionary and in the dictionary there is a…
Let's say I insert the document.
post = { some dictionary }
mongo_id = mycollection.insert(post)
Now, let's say I want to add a field and update it. How do I do that? This doesn't seem to work.....
post = mycollection.find_one({"_id":mongo_id})…
How to find names of all collections using PyMongo and find all fields in chosen collection ?
I have name of database and name of chosen collection. (Scenario : user input name of database, need to find all collections and show in dropdown list,…
I want to write a function to return all the documents contained in mycollection in mongodb
from pymongo import MongoClient
if __name__ == '__main__':
client = MongoClient("localhost", 27017, maxPoolSize=50)
db=client.mydatabase
…
I am trying to fetch some ids that exist in a mongo database with the following code:
client = MongoClient('xx.xx.xx.xx', xxx)
db = client.test_database
db = client['...']
collection = db.test_collection
collection = db["..."]
for cursor in…
I'm doing a python script that writes some data to a mongodb.
I need to close the connection and free some resources, when finishing.
How is that done in Python?
I have a document:
{ 'profile_set' :
[
{ 'name' : 'nick', 'options' : 0 },
{ 'name' : 'joe', 'options' : 2 },
{ 'name' : 'burt', 'options' : 1 }
]
}
and would like to add a new document to the profile_set set if the name doesn't…