mongoengine

MongoEngine: Adding Fields to Dynamic Document

天大地大妈咪最大 提交于 2019-12-24 08:57:28
问题 I would like to store dynamic fields to the document, but each document can have different fields. for eg: Class SampleDoc(DynamicDocument): xyz = StringField() df = "field1" a = SampleDoc() a.df = "testing" a.save() If i run the above program, the mongodb document looks like the following. { "_id" : ObjectId("53905681e5ba5b3bfd1f5242"), "_cls" : "DataPoint", "df" : "testing" } but what i want is that the field name should be "field1" instead of "df" like this.. { "_id" : ObjectId(

Flask and Gunicorn on Heroku import error

人走茶凉 提交于 2019-12-24 07:31:00
问题 I have a small Flask app which uses MongoEngine. my project structure: /myproject -application.py -config.py /my_app -models.py -views.py my application.py: #!/usr/bin/env python from flask.ext.mongoengine import MongoEngine from config import app import os app.debug = True # get config settings if __name__ == '__main__': app.config.from_object('config') else: app.config.from_object('heroku_config') # wrap app in mongengine db = MongoEngine(app) if __name__ == '__main__': # Bind to PORT if

Flask app broken after bson update in Heroku

风格不统一 提交于 2019-12-24 04:25:12
问题 I have a Flask app that uses mongoengine and running on Heroku, init I use the bson package and after I updateded it from 0.5.6 to 0.5.7 I started getting the following error message: [2018-11-23 05:56:43 +0000] [39] [INFO] Worker exiting (pid: 39) [2018-11-23 05:56:43 +0000] [40] [ERROR] Exception in worker process Traceback (most recent call last): File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/app/.heroku

Retrieving images from GridFS using django-tastypie-mongoengine

前提是你 提交于 2019-12-24 03:42:48
问题 I have a project in Django, and I'm using mongoengine to save images into a Mongo database using GridFSStorage. All ok so far, but the problem is... when trying to retrieve the images via http request, with a REST API made with django-tastypie-mongoengine, I get back a json object like this: {"file": "<GridFSProxy: 516ed7cf56ba7d01eb09f522>", "id": "516ed7cf56ba7d01eb09f524", "resource_uri": "/api/v1/pic/516ed7cf56ba7d01eb09f524/"} Does anybody know how could I get the file from GridFS via

How to Do An Atomic Update on an EmbeddedDocument in a ListField in MongoEngine?

折月煮酒 提交于 2019-12-24 01:54:26
问题 I've found some similar questions on StackOverflow, but nothing that addresses what I'm looking for, so any help would be appreciated. My models: class BlogPost(EmbeddedDocument): title = StringField(required=True) blog_url = StringField(required=True, unique=True) content = StringField() turned_into_bitly_link = BooleanField(default=False) class Person(Document): name = StringField blog_posts = ListField(EmbeddedDocumentField(BlogPost), default=list) For each blogpost.blog_url, I query the

Clone an existing document to a new sibling class document using mongoengine

蓝咒 提交于 2019-12-23 22:14:09
问题 I have the following classes class ParentDocument(Document): . . . class Child1Document(ParentDocument): . . . class Child2Document(ParentDocument): . . . Now let's say that I have a document of type Child1Document. Is it possible to clone it to a new document of type Child2Document? I have tried to do: doc1 = Child1Document() doc1.attr1 = foo doc1.save() doc2 = Child2Document() doc2 = doc1 but this converts doc2 to a Child1Document type. Is there a way to copy all the contents of doc1 to

MongoEngine: Close connection

半城伤御伤魂 提交于 2019-12-23 07:58:03
问题 I spent ages trying to find a simple example where MongoEngine was being used and a connection was being closed. Finally figured it out and posting my code. 回答1: I know this is an old question, but if anyone else is searching I figured I'd give an alternate answer. close() does not actually remove the connection from MongoEngine's connection list. This causes problems when trying to connect to a different database later on. To solve this I used mongoengine.connection.disconnect (even though

Filter list of embedded documents with reference field

霸气de小男生 提交于 2019-12-23 04:45:16
问题 I'm pretty new to MongoDB and I'm experiencing it with mongoengine. Given this 'User' model where 'bets' is an embedded document list which each element contains a reference to a 'match' document, { "_id" : ObjectId("53df77cef4c9610f28cbff14"), "name" : "Test", "admin" : false, "bets" : [ { "match" : ObjectId("53e1511df4c9610bf52f5b7a"), "expectedResult" : "1" } ] } how can I get 'bets' elements, passed to query the matchId? I tried to do User.objects.filter(bets__match={'match._id':match.id}

Django with MongoDB

喜欢而已 提交于 2019-12-23 03:37:20
问题 OK.. i am starting a project in django 1.4 and i want MongoDB as my backend. after a half a day of google search, i figured out that mongoengine is a best option(as it is an active project and provides a django like orm) Now the problem is 1. I cant find any good step-by-step setup guide to integrate mongoengine with a django project. I understand, using mongoengine means that i am replacing django orm and there is no need to do syncdb. now this project have a multi-tenant architecture (*

Deleting EmbeddedDocument with FileField from ListField

隐身守侯 提交于 2019-12-23 03:32:16
问题 In MongoEngine, when deleting an EmbeddedDocument from a ListField which includes a FileField, the referenced file does not get deleted. Currently, I have solved the issue by looping over the whole list field. for embdoc in doc.embdocs: if embdoc.filtered == value: embdoc.dfile.delete() doc.update(pull__embdocs={'filtered': value}) I was wondering if there was a better way to do this. 回答1: By default, MongoDB doesn’t check the integrity of your data, so deleting documents that other documents