Questions tagged [pymongo]

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.

Documentation

Related Links

Related Tags

6819 questions
2
votes
0 answers

Seeking understanding of the positional operator in the case of a single update of non-periodic time series segment

I'm experimenting with a schema for recording some non-periodic time series data using pymongo. There's a decent amount of stuff out there about periodic time series, but not too much for non-periodic. Taking a leaf from this post. In this schema,…
Travis Griggs
  • 21,522
  • 19
  • 91
  • 167
2
votes
1 answer

Aggregation in mongodb for nested documents

I have a document in the following format: "summary":{ "HUL":{ "hr_0":{ "ts":None, "Insights":{ "sentiments":{ "pos":37, "neg":3, …
Nitin Kumar
  • 765
  • 1
  • 11
  • 26
2
votes
1 answer

Client connection in Pymongo

How does MongoClient works and creates a connection pooling or thread creation? What are major resources used if a create a multiple connections? My main reson for asking is this ? I have created multiple classes in python which represents…
2
votes
0 answers

Can I use a field called size in a MongoEngine document?

I have a document: class Hamburger(Document): size = IntField(default=0, required=True) which I can use fine h = Hamburger() h.size = 5 h.save() until I try an update_one for example Hamburger.objects().update_one(set__size=5) which throws…
nickponline
  • 25,354
  • 32
  • 99
  • 167
2
votes
1 answer

Updating Nested Document In MongoDB using Pymongo

Following is the schema of the document I want to update: { "field1" : "value1", "field2" : "value2", "field3" : { "list" : [ { "content" : "valueA", "start" : "valueA", "group" : "valueA" …
Asad Baqri
  • 21
  • 1
  • 2
2
votes
2 answers

pymongo - TypeError: document must be an instance of dict, bson.son.SON, or other type that inherits from collections.MutableMapping

I'm writing data to MongoDB using pymongo. I receive this error when performing the write operation. TypeError: document must be an instance of dict, bson.son.SON, or other type that inherits from collections.MutableMapping If I print the data,…
Hydroxl
  • 69
  • 2
  • 7
2
votes
3 answers

Efficient way to aggregate in Mongodb

I have a collection { "name" : "foo" "clicked" : {"0":6723,"1": 1415,"2":1122} } { "name" : "bar" "clicked" : {"8":1423,"9": 1415,"10":1122} } { "name" : "xyz" "clicked" : {"22":6723,"23": 1415,"2":1234} } clicked is basically…
nimeshkiranverma
  • 1,408
  • 6
  • 25
  • 48
2
votes
1 answer

pymongo replication secondary readreference not work

we have MongoDB 2.6 and 2 Replica Set, and we use pymongo driver and connect Mongo Replicat Set with the following url mongodb://admin:admin@127.0.0.1:10011:127.0.0.1:10012,127.0.0.1:10013/db?replicaSet=replica with python code from pymongo import…
GCooper
  • 140
  • 6
2
votes
4 answers

Elasticsearch fails in parsing datetime field coming from pymongo as object

I am trying to stream data from a mongoDB to Elasticsearch using both pymongo and the Python client elasticsearch. I have set a mapping, I report here the snippet related to the field of interest: "updated_at": { "type": "date", …
mar tin
  • 9,266
  • 23
  • 72
  • 97
2
votes
2 answers

Finding number of inserted documents in a bulk insert with duplicate keys

I'm doing a bulk-insert into a mongodb database. I know that 99% of the records inserted will fail because of a duplicate key error. I would like to print after the insert how many new records were inserted into the database. All this is being done…
Claude
  • 8,806
  • 4
  • 41
  • 56
2
votes
1 answer

PyMongo, handling fields with time relative to the database time

Say I have a document field name "creation_time". I would like to have its value initialized with the database current time, instead using the client machine time with: datetime.datetime.utcnow() How can I achieve this with PyMongo? Moreover is…
sanyi
  • 5,999
  • 2
  • 19
  • 30
2
votes
1 answer

Can I continue using a pymongo cursor object after an AutoReconnect exception?

When you receive an AutoReconnect exception from a database query, a common practice is to wait a bit then try the query again (perhaps ad-infinitum in some contexts). If this happens while traversing a cursor, does it make sense to continue…
drevicko
  • 14,382
  • 15
  • 75
  • 97
2
votes
1 answer

querying mongodb using pymongo

i just started using mongodb and setup a test database to handle web scraping results from a couple scripts i created. right now, the date_found is being loaded as a string. when i run this in mongohub: {"date_found" : /.*2015-05-02.*/} i get all…
Silas
  • 89
  • 1
  • 7
2
votes
0 answers

how to connect to a remote mongodb server (hosted on google cloud)?

I hope you can help me on this particular problem. I use a windows virtual machine hosted on google cloud to stream some twitter data using the python code suggested here danielforsyth.me/analyzing-a-nhl-playoff-game-with-twitter. The twitter data…
ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
2
votes
1 answer

can I have a mongodb collection as a class attribute in python

I have the following class: import sys import os import pymongo from pymongo import MongoClient class Collection(): client = MongoClient() def __init__(self, db, collection_name): self.db = db self.collection_name =…
DBWeinstein
  • 8,605
  • 31
  • 73
  • 118