mongoengine

How atomic are mongoengine's operations

…衆ロ難τιáo~ 提交于 2019-12-12 19:11:20
问题 I'm trying to transition between object's state like so: User.objects(id=user_id, state=STATE_WAITING).update_one(set__state=STATE_FINISHED) The question is, can there be a situation where two processes will make the same operation asynchronously and succeed? If so, can this operation be atomic, so the next process that will try to update the user (at the same time asynchronously), will fail because it's status will be already "finished"? 回答1: When writing on a single document, the operation

Aggregation in flask-mongoengine

孤街醉人 提交于 2019-12-12 15:43:38
问题 I'm just staring out with MongoDB and I'm staring an application with flask-mongoengine and I want to aggregate a few documents. I'm using flask-mongoengine and when trying class MyDocumentModel(db.Document): name = db.StringField(max_length=55) MyDocumentModel.objects.aggregate() I get the error: AttributeError: 'BaseQuerySet' object has no attribute 'aggregate' 回答1: Starting with mongoengine v0.9 (which is currently in development), you will be able to use aggregate() , like you suggested:

Flask does not load configuration

…衆ロ難τιáo~ 提交于 2019-12-12 15:10:45
问题 I am facing trouble with loading configuration in Flask. from config import config, DevelopmentConfig, TestingConfig, ProductionConfig def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) # Doesnot load configuration app.config.from_object(DevelopmentConfig) # Loads configuration succesfully. I have checked the type of config[config_name] etc. They are just fine. config file is given as follow. There are no issues with import, object types. If passed

mongoengine.fields.ImproperlyConfigured: PIL library was not found

倖福魔咒の 提交于 2019-12-12 12:23:11
问题 When I try to import a MongoEngine class which has an ImageField, an error says: mongoengine.fields.ImproperlyConfigured: PIL library was not found My class structure is like this: class TrafficSign(Document): name = StringField() image = ImageField() type = StringField() desc = StringField() source = StringField() Whats the problem? 回答1: You need to install Pillow, which provides the PIL module. sudo pip install Pillow (drop the sudo if on Windows) ought to do it. 来源: https://stackoverflow

Mongoengine, retriving only some of a MapField

匆匆过客 提交于 2019-12-12 10:13:26
问题 For Example.. In Mongodb.. > db.test.findOne({}, {'mapField.FREE':1}) { "_id" : ObjectId("4fb7b248c450190a2000006a"), "mapField" : { "BOXFLUX" : { "a" : "f", } } } The 'mapField' field is made of MapField of Mongoengine. and 'mapField' field has a log of key and data.. but I just retrieved only 'BOXFLUX'.. this query is not working in MongoEngine.... for example.. BoxfluxDocument.objects( ~~ querying ~~ ).only('mapField.BOXFLUX') AS you can see.. only('mapField.BOXFLUX') or only only(

python wtf AttributeError: 'ObjectIdField' object has no attribute 'help_text'

安稳与你 提交于 2019-12-12 09:14:55
问题 Based on this tutorial I am trying to create a form to get a few measurements. It seems that the part to display the data is working but when using the model_form command to generate the input form it breaks with this error: File "/myproject/lib/python3.4/site-packages/flask_mongoengine/wtf/orm.py", line 49, in convert 'description': field.help_text or '', AttributeError: 'ObjectIdField' object has no attribute 'help_text' The error happens on this line of my code: form_cls = model_form

Mongoengine… query something not in a ListField?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 08:30:57
问题 for example.. class Page(Document) tags = ListField(StringField()) In this case, we can find out a value in the tags list like this. Page.objects(tags='coding') if tags are like ['coding', 'x', 'y'], then the document will be matched... but My question is how I can find out the value not in the listfield. my incorrect code would be.. Page.objects(tags!='coding') or Page.objects(tags__not = 'coding') or Page.objects(tags__not__in = 'coding') but.. they don't simply work.. how can I query a

How can I serialize a MongoDB ObjectId with Marshmallow?

喜你入骨 提交于 2019-12-12 07:59:15
问题 I'm building and API on top of Flask using marshmallow and mongoengine. When I make a call and an ID is supposed to be serialized I receive the following error: TypeError: ObjectId('54c117322053049ba3ef31f3') is not JSON serializable I saw some ways with other libraries to override the way the ObjectId is treated. I haven't figured it out with Marshmallow yet, does anyone know how to do that? My model is: class Process(db.Document): name = db.StringField(max_length=255, required=True, unique

How to search document by oid in mongoengine

▼魔方 西西 提交于 2019-12-12 07:57:50
问题 I need get documents from db by oid, like: Docs.objects(_id='4f4381f4e779897a2c000009') But how to do it, if _id requires ObjectId object and even I try to set ObjectId from pymongo it doesn't work. Docs.objects(_id=pymongo.objectid.ObjectId('4f4381f4e779897a2c000009')) return empty list 回答1: How about just using the raw string: Docs.objects.get(id='4f4381f4e779897a2c000009') That is probably the easiest way ... right ? 回答2: This should work: Docs.objects(pk='4f4381f4e779897a2c000009') 回答3:

MongoEngine - Deleted field still raises ValidationError

眉间皱痕 提交于 2019-12-12 04:32:14
问题 I'm using Flask with MongoEngine and as a test I tried to add a collection to MongoEngine with a few required fields in its schema by creating a Python file which contains a class that subclasses mongoengine.Document and has a few MongoEngine fields in it, which worked fine. But when I later removed some of those fields from the schema (just by editing the python class which subclasses mongoengine.Document) and tried to add new documents to the collection, MongoEngine threw ValidationErrors