pymongo

MongoDB MapReduce - Emit one key/one value doesnt call reduce

自闭症网瘾萝莉.ら 提交于 2021-02-05 18:52:12
问题 So i'm new with mongodb and mapreduce in general and came across this "quirk" (or atleast in my mind a quirk) Say I have objects in my collection like so: {'key':5, 'value':5} {'key':5, 'value':4} {'key':5, 'value':1} {'key':4, 'value':6} {'key':4, 'value':4} {'key':3, 'value':0} My map function simply emits the key and the value My reduce function simply adds the values AND before returning them adds 1 (I did this to check to see if the reduce function is even called) My results follow: {'

How to load data in MongoDB running in host from inside a Docker running on the same machine?

谁说胖子不能爱 提交于 2021-02-05 10:51:27
问题 I am running a Pytorch docker container by the following command in a Ubuntu 18.02 machine: # Run Pytorch container image docker run -it -v /home/ubuntu/Downloads/docker_work/test_py_app/app:/workspace/app -p 8881:8888 -p 5002:5002 --gpus all --rm nvcr.io/nvidia/pytorch:20.08-py3 On the same machine I've a MongoDB running, which has the following details: database_name = 'data_analytics' collection_name = 'TestDB' server = 'localhost' mongodb_port = 27017 I'm running the below code outside

How do I retrieve and print pymongo.cursor.Cursor objects?

霸气de小男生 提交于 2021-01-29 18:42:53
问题 I am creating a simple database CRUD manager using python and connecting it to a MongoDB database. I have connected to my cluster and have retrieved posts before using the exact same method. However this time when I tried, it does not work. The error is when I try to print the dictionary object from a collection. The collection only contains a single object with {title:"book"} In the following code, I have retrieved a pymongo.cursor object as the variable name "thedb". print(thedb) will

mongodb mongoengine filter document on nexted EmbeddedDocumentLIst fields

本秂侑毒 提交于 2021-01-29 15:23:10
问题 I have a document with a EmbeddedDocumentList inside an other EmbeddedDocumentlist, I need to filter the collections retrieving only the documents that have a specified value for a field inside the inner EmbeddedDocumentList the reduced version of my models is: class RecipeIngredient(EmbeddedDocument): ingredient = ReferenceField(Ingredient, required=True) quantity = IntField(required=True) class RecipeLocalData(EmbeddedDocument): price = FloatField(required=True) enabled = BooleanField

Import MongoDB data to Azure ML Studio from Python Script

丶灬走出姿态 提交于 2021-01-29 08:17:50
问题 Currently in Azure ML's while executing python script, with following code. (Python 2.7.11) In which results obtained from the mongoDB are trying to return in DataFrame using pyMongo. I got an error like :: "C:\pyhome\lib\site-packages\pymongo\topology.py", line 97, in select_servers self._error_message(selector)) ServerSelectionTimeoutError: ... ('The write operation timed out',) Please let me know if you know about the cause of the error and what to improve. My Source code : import pymongo

Adding Object in Array PyMongo

对着背影说爱祢 提交于 2021-01-29 05:19:09
问题 How do I achieve a structure like following in Python? Help appreciated! 回答1: Here's an example to demonstrate $push : from pymongo import MongoClient client = MongoClient() db = client.test_db movies = db.movies inserted_id = movies.insert_one({ 'name': 'Movie 1', 'reviews': [] }).inserted_id movies.update_one({'_id': inserted_id}, { '$push': { 'reviews': [ { 'listing_id': '1', 'reviewer_id': 'r1' } ] } }) Output from mongo console: > db.movies.findOne() { "_id" : ObjectId(

How to get set of missing consecutive numbers array only has low and high mongodb

无人久伴 提交于 2021-01-29 05:04:29
问题 I am trying to get sets of having an array of missing consecutive numbers only has [low, high] Example, mongodb collection 'meta_import' has these numbers: [1,2,3,4,7,8,100,101,200,400,401,403] I want to get [[5,6], [9,99], [102,199], [201,399], [402]] I have tried: var pipe = [ {'$group' : {'_id' : null, min : {'$min' : "$num"}, max : {'$max' : "$num"}}}, {'$addFields' : {'rangeIds' : {'$range' : ["$min", "$max"]}}}, {'$lookup' : {'from' : "meta_import", localField : "rangeIds", foreignField

Flask & MongoDB - For Loop not working

戏子无情 提交于 2021-01-29 03:14:54
问题 Having this for Flask: example = mongo.db.example got_name = example.find({'name':1}) got_lastname = example.find({'lastname':1}) details = {'name' : got_name, 'lastname' : got_lastname} return render_template('blabla.html', details=details) Then the for loop using Jinja in my HTML (wanting it to be a table): {% for x in details} <tr> <td>{{ x.['name'] }}</td> <td>{{ x.['lastname'] }}</td> </tr> {% endfor %} But it won't work, it doesn't display anything in my table. I wrote this example

How to retrieve each single array element from mongo pipeline?

余生长醉 提交于 2021-01-28 00:44:34
问题 Let's assume that this is how a sample document looks like in mongo-db, [ { "_id": "1", "attrib_1": "value_1", "attrib_2": "value_2", "months": { "2": { "month": "2", "year": "2008", "transactions": [ { "field_1": "val_1", "field_2": "val_2", }, { "field_1": "val_4", "field_2": "val_5", "field_3": "val_6" }, ] }, "3": { "month": "3", "year": "2018", "transactions": [ { "field_1": "val_7", "field_3": "val_9" }, { "field_1": "val_10", "field_2": "val_11", }, ] }, } } ] The desired output is

Can't create index due to TypeError: not enough arguments for format string

偶尔善良 提交于 2021-01-27 17:08:00
问题 I am trying to create indices with pymongo, but failing with error File "D:/Users/Dims/Design/EnergentGroup/Python GIS Developer/worker/Approach03\sentinel\mongo.py", line 46, in get_results_collection results_collection.create_index(["uwi", "date_part"], name=index_name, unique=True) File "C:\Anaconda3\lib\site-packages\pymongo\collection.py", line 1386, in create_index name = kwargs.setdefault("name", helpers._gen_index_name(keys)) File "C:\Anaconda3\lib\site-packages\pymongo\helpers.py",