pymongo

Unable to serialize JSON object from MongoDB in python

点点圈 提交于 2019-12-08 01:16:24
问题 I have the following JSON stored in my MongoDB: { "_id" : ObjectId("54fed786265e7f01d66ca778"), "id" : "http://some.site.somewhere/entry-schema#", "schema" : "http://json-schema.org/draft-04/schema#", "description" : "schema for an fstab entry", "type" : "object", "required" : [ "storage" ], "properties" : { "storage" : { "type" : "object", "oneOf" : [ DBRef("#/definitions/diskDevice", 1), DBRef("#/definitions/diskUUID", 2), DBRef("#/definitions/nfs", 3), DBRef("#/definitions/tmpfs", 4) ] } }

How to format data for MongoEngine PointField

*爱你&永不变心* 提交于 2019-12-07 22:29:45
问题 So I wanted to do some experiments with location data in mongodb, so I wrote some python code to generate some testing data. Unfortunately the documentation at http://docs.mongoengine.org/apireference.html#mongoengine.fields.PointField isn't explicit about how to format the input. class Location(db.Document): coord = db.PointField(required=True) # GeoJSON Trying to store a list containing the lng/lat fails: >>> a = Location(coord=[1,2]) >>> a.save() mongoengine.errors.OperationError: Could

pymongo和mongoengine安装和使用教程 包含常用命令行和代码示例

和自甴很熟 提交于 2019-12-07 19:37:09
本文首发于个人博客 https://kezunlin.me/post/e88f04e5/ ,欢迎阅读最新内容! pymongo and mongoengine tutorial on ubuntu 16.04 Guide version mongo 2.6.10 mongo gui: robo3t-1.3.1 pymongo 3.9.0 MongoEngine 0.18.2 install mongodb sudo apt-get install -y mongodb mongo shell mongo --host mongodb0.example.com --port 27017 mongo --version MongoDB shell version: 2.6.10 see mongo shell > mongo # show all dbs > show dbs # display current db >db test (default database) # switch or create db > use mydb > db.help() > show collections posts system.indexes > db.posts.help() > db.posts.find() help on db and collections >db

pymongo和mongoengine安装和使用教程 包含常用命令行和代码示例

浪子不回头ぞ 提交于 2019-12-07 19:34:25
本文首发于个人博客 https://kezunlin.me/post/e88f04e5/ ,欢迎阅读最新内容! pymongo and mongoengine tutorial on ubuntu 16.04 Guide version mongo 2.6.10 mongo gui: robo3t-1.3.1 pymongo 3.9.0 MongoEngine 0.18.2 install mongodb sudo apt-get install -y mongodb mongo shell mongo --host mongodb0.example.com --port 27017 mongo --version MongoDB shell version: 2.6.10 see mongo shell > mongo # show all dbs > show dbs # display current db >db test (default database) # switch or create db > use mydb > db.help() > show collections posts system.indexes > db.posts.help() > db.posts.find() help on db and collections >db

How can I execute a JS script file from Pymongo?

笑着哭i 提交于 2019-12-07 19:26:22
问题 I have a MapReduce job for my MongoDB database implemented in a Javascript script file. I've tested it from the commandline and Mongo shell ( load("MR_stack.js") ). Now I'm using Pymongo within a larger application to access the Mongo database. How can I execute my MR_stack.js script from within Pymongo? 回答1: The database object has an eval method: http://api.mongodb.org/python/current/api/pymongo/database.html 回答2: Well, your favorite option is to read existing documentation: http://api

MongoDB Query - limit fields where name matches pattern

风格不统一 提交于 2019-12-07 18:52:08
问题 I've read everything I can find about Projection in MongoDB. I'm hoping this is simple and I just missed it due to the overwhelming flexibility of Mongo queries. In our MySql database, we've adopted a business practice of having "hidden" fields be prefixed with an underscore. Our application knows how to hide these fields. Moving some data to mongo, I need to retrieve the documents, with ALL underscore prefixed fields omitted . Of course this should be done in the query rather than document

PyMongo Cursor Iteration

混江龙づ霸主 提交于 2019-12-07 17:35:24
问题 I'm looking to create and handle a cursor in python the way cursors natively work in mongo. I know the intended way is to do 'result = collection.find()' and do a 'for record in result' but I'm looking to wrap iteration functionality in a class. I'd like to be able to create a new class object and call a function e.g. init_cursor() to make a db connection and do a find returning a cursor. I would then like the have a get_next() function that would move to the next result and set class data

pymongo.errors.BulkWriteError: batch op errors occurred (MongoDB 3.4.2, pymongo 3.4.0, python 2.7.13)

爷,独闯天下 提交于 2019-12-07 16:57:52
问题 I am migrating several hundred million tweets of the format {'id_str': , 'created_at': , 'text': } from text files into MongoDB using pymongo. A collection is created for each user to store his/her tweets. The insertion method I am using is insert_many() . It often runs into BulkWriteError . Traceback (most recent call last): File "pipeline.py", line 105, in <module> timeline_db, meta_db, negative_db, log_col, dir_path) File "/media/haitao/Storage/twitter_pipeline/migrate_old.py", line 134,

nested queries in pymongo using collection.find()

我与影子孤独终老i 提交于 2019-12-07 16:13:57
问题 I would like to create a data base using mongodb and I am wondering how to query nested entities. For instance, let's assume we create a db as follows: from pymongo import MongoClient db = client['test_database'] collection = db['test_collection'] dat=[ { "id":110, "data":{"Country":"ES","Count":64}}, { "id":112, "data":{"Country":"ES","Count":5}}, { "id":114, "data":{"Country":"UK","Count":3}} ] collection.insert(dat) how can we query the records with "Country" values "ES"? Or alternatively

How to improve a XML import into mongodb?

ぃ、小莉子 提交于 2019-12-07 14:29:40
问题 I have some large XML files (5GB ~ each) that I'm importing to a mongodb database. I'm using Expat to parse the documents, doing some data manipulation (deleting some fields, unit conversion, etc) and then inserting into the database. My script is based on this one: https://github.com/bgianfo/stackoverflow-mongodb/blob/master/so-import My question is: is there a way to improve this with a batch insert ? Storing these documents on an array before inserting would be a good idea ? How many