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
0
votes
1 answer

Aggregate - count records with pymongo

I would like to count matching records with pymongo. I have looked up the documentation: https://docs.mongodb.com/manual/reference/operator/aggregation/group/#group-by-month-day-and-year I understand that I should do something…
user1747134
  • 2,374
  • 1
  • 19
  • 26
0
votes
1 answer

pymongo wont work :( Tried everything

Hi little frusutriated here, any help would be amazing hi I am using Windows Server 2012 R2 I have installed python 2.7.13 C:\Python27>python -c "import sys; print(sys.version)" 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit…
Jack G
  • 71
  • 2
  • 9
0
votes
1 answer

How can I force pymongo to close sockets?

I'm currently working on distributed computing. My workers returns its results by inserting it into a mongoDB database.The code works well,but the connection remains opened and at a moment my system run out of sockets. Here is my worker code: def…
0
votes
1 answer

Pymongo Read Preferences - ServerSelectionTimeoutError: No primary available for writes

When connection to a MongoDB replica set, I'm able to read from the secondaries, but afterwards, when writing using the same connection, I receive the following error: pymongo.errors.ServerSelectionTimeoutError: No primary available for…
Nadav
  • 574
  • 10
  • 24
0
votes
0 answers

pymongo find().hint('index') does not use index

I am trying to use an index to access documents in a collection using a particular index in Python 3.5 with Pymongo 3.3.0 and Mongodb 3,2. I created a field called sequence in each document that contains a number defining the load order of the…
Jonathan
  • 2,635
  • 3
  • 30
  • 49
0
votes
2 answers

Update ok in mondb client but KO in Python

Newbie in mongodb/python/pymongo. My mongodb client code works OK. Here it is : db.meteo.find().forEach( function(myDoc) { db.test.update({"contract_name" : myDoc.current_observation.observation_location.city}, { $set: {…
Cop
  • 1
0
votes
2 answers

python 3.6 mongoengine cannot catch exception

I have a django 1.9 project and am using mongoengine to connect to mongodb instance. I have a model as follows: from django.db import models from mongoengine import * class Employee(Document): email = StringField(required=True, unique=True) …
Kheshav Sewnundun
  • 1,236
  • 15
  • 37
0
votes
0 answers

How to enable `projection` in pymongo query class `find()`?

find() official link for doc in db.tasks.find(filter={'state':'successful'},projection=['analysis.bandgap'])‌​: print doc I tried to set projection as a list or dict, but neither will work for limit the output of find(). How to set projection…
keliu
  • 41
  • 3
0
votes
1 answer

I am using jupyter to edit, but after import pymongo , why can't list the data I stored in MongoDB?

I am just the beginner of python, so sorry about this basic problem enter image description here import pymongo client = pymongo.MongoClient('localhost', 27017) ceshi = client['ceshi'] item_info = ['item_info3'] for i in item_info: if…
shally
  • 1
  • 4
0
votes
1 answer

How to insert_many with txMongo avoiding duplicated keys?

I'm trying to insert a list of documents in MongoDB, each document has the field "_id". So when I send a list like this [{"_id":"2"}, {"_id":"1"}, {"_id":"3"}] And at least one of the _id's is already in the DB, it shows an…
Jimmy A. León
  • 541
  • 3
  • 6
  • 22
0
votes
1 answer

Bulk Import JSON documents into MongoDB

I have a directory with 18K json documents. I'm trying to do a bulk import into MongoDB. I wrote this script in Python to load everything in. This code gives me a syntax error since it doesn't seem that Pymongo has 'mongoimport' function. How would…
Yolo49
  • 489
  • 2
  • 7
  • 14
0
votes
1 answer

How to create a datetime object within a pymongo pipeline?

I have some code where I set up the following pipeline: filter collection, project year & month, group by year & month, and then finish with a datetime object like YYYY-MM-01. Example Document: { _id: 123456 foo: "bar" dt:…
timctran
  • 505
  • 4
  • 10
0
votes
0 answers

ImportError: cannot import name MongoClient

I just installed and pymongo for the first time and immediately had trouble. When running the example from the basic python tutorial on the MongoDB website I immediately get this response: Traceback (most recent call last): File "pymongo.py", line…
hegemonni
  • 1
  • 1
0
votes
1 answer

Mongodb lock prevention

After some time looking at the mongodb documentation and the pymongo API, I am still no clearer on what route I take as the way forward (more confused now that when I started) . My problem concerns locks ... not so much that I have tested and found…
ajsp
  • 2,512
  • 22
  • 34
0
votes
1 answer

Getting a distinct aggregation elements of array by index

client = MongoClient() db = client['test'] connection = db['test'] conn.insert({"tags": ["first_1", "second_1"]}) conn.insert({"tags": ["first_2", "second_1"]}) conn.insert({"tags": ["first_3", "second_2"]}) print conn.distinct("tags") I got as…
El Ruso
  • 14,745
  • 4
  • 31
  • 54
1 2 3
21
22