Questions tagged [pymongo-3.x]

Version 3 of [pymongo]

Version 3 of the official Python driver for MongoDB.

PyMongo 3 is not backward compatible with PyMongo 2:

PyMongo 3.0 brings a large number of API changes. Be sure to read the changes listed below before upgrading from PyMongo 2.x

Warning: PyMongo no longer supports Python 2.4, 2.5, or 3.1. If you must use PyMongo with these versions of Python the 2.x branch of PyMongo will be minimally supported for some time.

See the full changelog for more information.

If you're not sure what version of PyMongo you're running, consider using the generic tag.

324 questions
72
votes
29 answers

Why is PyMongo 3 giving ServerSelectionTimeoutError?

I'm using: Python 3.4.2 PyMongo 3.0.2 mongolab running mongod 2.6.9 uWSGI 2.0.10 CherryPy 3.7.0 nginx 1.6.2 uWSGI start params: --socket 127.0.0.1:8081 --daemonize --enable-threads --threads 2 --processes 2 I setup my MongoClient ONE…
drfence
  • 1,487
  • 2
  • 17
  • 29
33
votes
5 answers

How to escape @ in a password in pymongo connection?

My question is a specification of how can i validate username password for mongodb authentication through pymongo?. I'm trying to connect to a MongoDB instance using PyMongo 3.2.2 and a URL that contains the user and password, as explained in…
gmauch
  • 1,316
  • 4
  • 25
  • 39
31
votes
2 answers

How to set connection timeout for Mongodb using pymongo?

I tried setting connectTimeoutMS and socketTimeoutMS to a low value but it still takes about 20 seconds before my script times out. Am I not using the options correctly? I want the script to exit after 5 seconds. def init_mongo(): …
sdot257
  • 10,046
  • 26
  • 88
  • 122
16
votes
7 answers

PyMongo [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate

I'm using Python 3.9.5 and PyMongo 3.11.4. The version of my MongoDB database is 4.4.6. I'm using Windows 8.1 I'm learning MongoDB and I have a cluster set up in Atlas that I connect to. Whenever I try to insert a document into a collection, a…
MaxwellN
  • 707
  • 1
  • 5
  • 13
16
votes
7 answers

How to dump a collection to json file using pymongo

I am trying to dump a collection to .json file but after looking in pymongo tutorial I can not find any thing that relates to it. Tutorial link: https://api.mongodb.com/python/current/tutorial.html
AnhNg
  • 179
  • 1
  • 1
  • 7
14
votes
2 answers

Why is PyMongo count_documents is slower than count?

In db['TF'] I have about 60 million records. I need to get the quantity of the records. If I run db['TF'].count(), it returns at once. If I run db['TF'].count_documents({}), that is a such long time before I get the result. However, the count method…
Threegirl
  • 143
  • 1
  • 1
  • 4
14
votes
1 answer

How to count pymongo aggregation cursor without iterating

I want to get the total number of records in an aggregate cursor in pymongo version 3.0+. Is there any way to get total count without iterating over the cursor? cursor = db.collection.aggregate([{"$match": options},{"$group": {"_id":…
jadhavmahendra7
  • 141
  • 1
  • 5
13
votes
1 answer

Pymongo $in Query Not Working

Seeing some strange behavior in Pymongo $in query. Looking for records that meet the following query: speciesCollection.find({"SPCOMNAME":{"$in":['paddlefish','lake sturgeon']}}) The query returns no records. If I change it to find_one the it…
Jer
  • 133
  • 1
  • 1
  • 6
13
votes
1 answer

insert_many with upsert - PyMongo

I have some data like this: data = [{'_id': 1, 'val': 5}, {'_id': 2, 'val': 1}}] current data in db: >>> db.collection.find_one() {'_id': 1, 'val': 3} I always receive unique rows but am not sure if any of them already exists in DB…
Kevad
  • 2,781
  • 2
  • 18
  • 28
11
votes
2 answers

Bulk update in Pymongo using multiple ObjectId

I want to update thousands of documents in mongo collection. I want to find them using ObjectId and then whichever document matches , should be updated. My update is same for all documents. I have list of ObjectId. For every ObjectId in list, mongo…
Pratik Gujarathi
  • 929
  • 1
  • 11
  • 20
10
votes
2 answers

PyMongo find query returns empty/partial cursor when running in a Django+uWsgi project

We developed a REST API using Django & mongoDB (PyMongo driver). The problem is that, on some requests to the API endpoints, PyMongo cursor returns a partial response which contains less documents than it should (but it’s a completely valid JSON…
Shahin
  • 1,415
  • 4
  • 22
  • 33
8
votes
1 answer

How to cleanly shutdown Change Streams with Motor?

TL; DR This was indeed a bug in Motor 1.2.0 that was promptly fixed by A. Jesse Jiryu Davis and is available in version 1.2.1 or greater of the driver. Original Question I wrote a program to monitor changes to a MongoDB collection using its new…
Rafa Viotti
  • 9,998
  • 4
  • 42
  • 62
7
votes
1 answer

Python pyodbc.row to list

I am trying to create a python script to convert from SQLServer database to Mongodb. In the query from SQLServer, I am returning the data as JSON using the FOR JSON AUTO method. When I use the following code, I cannot get the right type for my var…
Heath
  • 153
  • 2
  • 2
  • 13
7
votes
1 answer

Pymongo's update_one() returns UpdateResult with AttributeError

I just upgraded my MongoDB and Pymongo to the latest version 3.2.1 to be able to use the UpdateResult object after calling update_one(). But for some reason the returned object has one field that contains an AttributeError. Take a look at my Pycharm…
BeePi
  • 343
  • 1
  • 2
  • 8
6
votes
6 answers

Pymongo: Best way to remove $oid in Response

I have started using Pymongo recently and now I want to find the best way to remove $oid in Response When I use find: result = db.nodes.find_one({ "name": "Archer" } And get the response: json.loads(dumps(result)) The result would be: { "_id":…
KitKit
  • 8,549
  • 12
  • 56
  • 82
1
2 3
21 22