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 don't understand the difference between create_index and ensure_index in pymongo. On the MongoDB indexes page, it says
you can create an index by calling the
ensureIndex()
However in pymongo there are two different commands create_index and…
How can I do a bulk upsert in pymongo? I want to Update a bunch of entries and doing them one at a time is very slow.
The answer to an almost identical question is here: Bulk update/upsert in MongoDB?
The accepted answer doesn't actually answer the…
I'm using mongodb and I store datetime in my database in this way
for a date "17-11-2011 18:00" I store:
date = datetime.datetime(2011, 11, 17, 18, 0)
db.mydatabase.mycollection.insert({"date" : date})
I would like to do a request like that
month =…
I need to check if a find statement returns a non-empty query.
What I was doing was the following:
query = collection.find({"string": field})
if not query: #do something
Then I realized that my if statement was never executed because find returns a…
I want to add a record to the collection if the key doesn't already exist. I understand [MongoDB][1] offers the upsertfor this so I did a
db.collection.update({"_id":"key1"},{"_id":"key1"},True)
This seems to work.
However in the Pymongo…
I am trying to retrieve data from mongodb with python. My db contains lots of data. So I want to limit the data while retrieving. I tried
import datetime
from pymongo import Connection
connection = Connection('localhost',27017)
db =…
I have a list of mongo '_id' which I want to delete. Currently I am doing this
# inactive_users --> list of inactive users
for item in inactive_users:
db.users.remove({'_id' : item})
but my problem is the list is too huge... (it might go…
I am using pymongo and want to have distinct values for a field such that I can also pass other query parameters. For example, I have entries like:
{
id = "my_id1"
tags: [tag1, tag2, tag3],
category: "movie",
}
{
id = "my_id2"
tags:…
I've been trying to find a way to create an ISODate object whith pyMongo client, but without any success so far.
I use http://pypi.python.org/pypi/pymongo3 client, which is the only serious one available in Python 3 for now, but the problem doesn't…
I have installed mongodb and enabled auth. and its working find. I can connect it from remote notebook using robomongo application:
Host: SERVER_IP
PORT: 27017
DATEBASE: prod-db
USERNAME: user_name
PASS: user_password
Auth Mechanism: MONGODB-CR
and…
I've this query:
produits = yield motor.Op(db.users.aggregate, [{"$unwind":"$pup"},{"$match":{"pup.spec.np":nomp}}, {"$group":{"_id":"$pup.spec.id","pup":{"$push":"$pup"}}}])
which gives me this result:
print produits
{u'ok': 1.0, u'result':…
I have a problem running pymongo on Win 7 (64) with Python 3.4, mongodb 4.2.10.
The error output is as follows:
import pymongo
ImportError: No module named 'pymongo'
The code is pretty simple:
import pymongo
from pymongo import…
I want to enable text-search at a specific field in my Mongo DB. I want to implement this search in python (-> pymongo). When I follow the instructions given in the internet:
db.foo.ensure_index(('field_i_want_to_index', 'text'),…