pymongo

Mongodb update with upsert fails

可紊 提交于 2020-01-06 04:57:32
问题 Here is the statement which fails: db.some_collection.update(query,modifier_set, upsert=True, safe=True) modifier_set is of the form {"$inc":{...}, "$addToSet":{...}} I get an OperationFailure error: $ operator made object too large Now, it's highly unlikely that my document it more that 16MB. Any other possible reasons for such failure ? 回答1: It is actually a case of oversized document. db.collection_name.stats() confirmed it. 来源: https://stackoverflow.com/questions/11224942/mongodb-update

E11000 duplicate key error index pymongo

情到浓时终转凉″ 提交于 2020-01-06 03:36:50
问题 So a little background, Ive worked with mongodb before in node.js with mongoose.js. And now I decided to try out to work with python and pymongo. But when I try to insert a document in to my collection I just get a error off: pymongo.errors.DuplicateKeyError: E11000 duplicate key error index: database.emails.$email_1 dup key: { : "mail@example.com" } I have been looking araund on the internet for a solution both in python but allso in other languages. It might very well be that sense iv only

pymongo saving embedded objectIds, InvalidDocumentError

做~自己de王妃 提交于 2020-01-05 12:23:50
问题 Using the pymongo driver bare to connect python to mongodb, why is it that using an ObjectId instance as the key for an embedded document raises an InvalidDocument error? I am trying to link documents using objectids and cant seem to understand why I would want to convert them to strings when the ones created automatically for the driver are ObjectId instances. item = collection.find({'x':'foo'}) item['otherstuff'] = {pymongo.objectid.ObjectId() : 'data about this link'} collection.update({'x

MongoDB connection reset by peer

做~自己de王妃 提交于 2020-01-05 06:54:27
问题 I've looked at other solutions to this, such as: Mongodb: Connection reset by peer Mongodb : AutoReconnect, Connection reset by peer But still have this error. I'm trying to load a large GeoJSON file into MongoDB. Here's my code: https://gist.github.com/mittenchops/6499844 using the iterative json parser here: https://github.com/isagalaev/ijson Here is my error: Traceback (most recent call last): File "upload2mongo.py", line 57, in <module> main(sys.argv) File "upload2mongo.py", line 52, in

Skip and Limit for pagination for a Mongo aggregate

北城余情 提交于 2020-01-05 03:39:53
问题 I am working on pagination in flask(Python framework) using flask-paginate (just for ref) I am able to achieve pagination for just a find query as below: from flask_paginate import Pagination from flask_paginate import get_page_args def starting_with_letter(letter): page, per_page, offset = get_page_args() collection_name=letter.lower()+'_collection' words=db[collection_name] data_db=words.find() data=data_db.limit(per_page).skip(offset) '''Here I have achieved the limit and skip'''

Serializing MongoDB find() return into non-anonymous JSON array, using PyMongo

∥☆過路亽.° 提交于 2020-01-04 14:29:09
问题 My Python code queries a MongoDB and gets back an array of the following objects: { u'attribute': u'value', u'_id': ObjectId('534776c66e5987041f6154bd') } What I want to achieve, is to return the following JSON: { 'mycollectionkey' : [ { 'attribute':'value', '_id': ObjectId('534776c66e5987041f6154bd') }, ...and so on. ] } However, when I do: docs = mongodb.find(...query...) docs_json = bson.json_util.dumps(docs) return flask.jsonify(success=True,mycollectionkey=docs_json) I get: {

how to query an element from a list in pymongo

独自空忆成欢 提交于 2020-01-03 08:58:47
问题 pymongo throws me an error when trying to query and element from tags db.users.find({"pseudo":"alucaard"}).distinct("produit_up") Out[1]: [{u'abus': 0, u'avctype': u'image/jpeg', u'date': u'2012-09-15', u'description': u'le fameux portable solide', u'id': u'alucaard134766932677', u'namep': u'nokia 3310', u'nombre': 1, u'orientation': u'portrait', u'photo': ObjectId('5053cd4e3a5f3a0990da8a61'), u'prix': 1000, u'tags': [u'solide', u'le', u'fameux', u'portable'], u'vendu': False}] list(db.users

What's the error in my project?

随声附和 提交于 2020-01-03 05:17:06
问题 I'm using mongodb for my python(2.7) project with django framework..when i give python manage.py runserver it will work but if i sync the db (python manage.py syncdb) the following error displayed in terminal Creating tables ... Traceback (most recent call last): File "manage.py", line 14, in <module> execute_manager(settings) File "/usr/lib/pymodules/python2.7/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/usr/lib/pymodules/python2.7/django/core

Writing big unsigned int64 to mongoDB with pymogno

空扰寡人 提交于 2020-01-03 04:52:07
问题 I have a number I'm getting from an external source I want to write to the mongo as Int The problem is that the number is above signed Int64 (which is how mongo implements it) - but is still fits unsinged int64 The number is: 9223372036854776000 How can I still write it to mongo? I'm getting OverflowError: MongoDB can only handle up to 8-byte ints 回答1: With the latest PyMongo and MongoDB 3.4 or later, you can use the standard Python Decimal with the new BSON Decimal128 type. from decimal

ImportError: No module named parse

半世苍凉 提交于 2020-01-02 08:55:17
问题 I am trying to run web application using mongodb and pymongo to serve data from database. The error I am getting is ImportError: No module named parse. Please see below error.log from apache2 web server: mod_wsgi (pid=18824): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module. [:error] [pid 18824:tid 139967053518592] mod_wsgi (pid=18824): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'. [:error] [pid 18824:tid 139967053518592]