mongoengine

MongoEngine delete document

MongoEngine delete document Question: I have the following MongoEngine document { ‘_id’: ‘some_id’, ‘data’: ‘some_data’ } How can I delete this document using MongoEngine? What I’ve tried: import my_collection obj = my_collection.MyCol.objects.get(_id=’some_id’) # obj is correctly found – let’s continue obj.delete() # mongoengine.errors.ValidationError: ‘None’ is not a valid ObjectId obj.delete(‘some_id’) # TypeError: delete() takes 1 …

Total answers: 6

How to get dictionary object in Mongoengine Python?

How to get dictionary object in Mongoengine Python? Question: On querying pymongo i get a dictionary object that can be sent directly as a response to the api request. Where as mongoengine returns a Document object on querying database. So I have to parse every object before it can be sent as the response in …

Total answers: 2

Mongoengine: ConnectionError: You have not defined a default connection

Mongoengine: ConnectionError: You have not defined a default connection Question: In my new Django project I set up a MongoDB database and use mongoengine module but I can’t properly access the dabase neither in shell nor in views. "ConnectionError: You have not defined a default connection" My settings.py includes the following: DATABASES = { ‘default’: …

Total answers: 4

Convert mongodb return object to dictionary

Convert mongodb return object to dictionary Question: I’m using the bottle framework together with mongoengine. I have an orders model : class OrderDetail(Option): orderDetailsQty = FloatField() def to_dict(self): return mongo_to_dict_helper(self) class Order(Document): userName = StringField(required=True) orderDate = DateTimeField() orderStatus = ListField(EmbeddedDocumentField(Status)) orderDetails = ListField(EmbeddedDocumentField(OrderDetail)) orderComments = ListField(EmbeddedDocumentField(Comment)) isActive = BooleanField() def to_dict(self): orderObj = mongo_to_dict_helper(self) …

Total answers: 7

Flask throwing 'working outside of request context' when starting sub thread

Flask throwing 'working outside of request context' when starting sub thread Question: I am trying to start a new thread in Python inside of a Flask application. I am doing background work that gets triggered by the request, but I don’t need to wait for the work to be done to respond to the request. …

Total answers: 5

Mongoengine creation_time attribute in Document

Mongoengine creation_time attribute in Document Question: I am trying to add a creation_time attribute to my documents. The following would be an example: import datetime class MyModel(mongoengine.Document): creation_date = mongo.DateTimeField() modified_date = mongo.DateTimeField(default=datetime.datetime.now) Django models have built in parameter for their DateTimeField objects like add_now, etc., but MongoEngine does not support this. I am wondering …

Total answers: 9

PyMongo vs MongoEngine for Django

PyMongo vs MongoEngine for Django Question: For one of my projects I prefered using Django+Mongo. Why should I use MongoEngine, but not just PyMongo? What are advantages? Querying with PyMongo gives results that are allready objects, aren’t they? So what is the purpose of MongoEngine? Asked By: megido || Source Answers: I assume you have …

Total answers: 4