» Django with Pluggable MongoDB Storage troubles
Django with Pluggable MongoDB Storage troubles
|February 18, 2011
Posted by forumadmin
I’m trying to use django, and mongoengine to provide the storage backend only with GridFS. I still have a MySQL database.
I’m running into a strange (to me) error when I’m deleting from the django admin and am wondering if I am doing something incorrectly.
my code looks like this:
from mongoengine import connect
from mongoengine.django.storage import GridFSStorage
name = models.CharField(max_length=50)
content = models.FileField(upload_to="appsfiles", storage=GridFSStorage())
creation_time = models.DateTimeField(auto_now_add=True)
last_update_time = models.DateTimeField(auto_now=True)
I am able to upload files just fine, but when I delete them, something seems to break and the mongo database seems to get in an unworkable state until I manually delete all FileDocument.objects. When this happens I can’t upload files or delete them from the django interface.
From the stack trace I have:
/home/projects/vector/src/mongoengine/django/storage.py in _get_doc_with_name
doc = [d for d in docs if getattr(d, self.field).name == name] ...
▼ Local vars
Error in formatting: cannot set options after executing query
/home/projects/vector/src/mongoengine/fields.py in __getattr__
Am I using this feature incorrectly?
thanks to @zeekay’s answer I was able to get a working gridfs storage plugin to work. I ended up not using mongoengine at all. I put my adapted solution on github. There is a clear sample project showing how to use it. I also uploaded the project to pypi.
I’d highly recommend the django-storages project. It has lots of storage backed options and is used by many more people than my original proposed solution.
More Related Questions
- Mongoengine get latest() In django how to get latest instance of a query set if i'm using MongoEngine
Normally we do
But i cant use latest in MongoEngine.
;) . i'm in stuck .
- ValidationError (StringField only accepts string values: [field_name]) Here is Django model
#copy_history = EmbeddedDocumentField(VkCopyHistory, required=False)
owner_id = StringField(db_field='owner_id', […]
- MongoDB: querying fields of a referenced document I'm writing a Flask app that reports on different metrics relating to content items (e.g. number of views). The metrics data is imported from various sources, and I'm using MongoDB to […]
- Using GridFS – Should it be on a separate DB? I am making a site that has a lot of audio storage, terabytes, and I was wanting to use GridFS for sharding and to be able to easily expand the database across multiple machines.
- GridFS and Cloning to another server I have a local MongoDB database that I am starting to put some files into GridFS for caching purposes. What I want to know is:
Can I use db.cloneCollection() on another server to clone my […]
- How to confirm user created by create_user in flask security mongoengine app? I have a python flask app using mongoengine and flask security built up from the examples to expose all of the confirmation, registration, tracking, and recovery functionality.
- How can I backup a MongoDB GridFS database the easiest way? Like the title says, I have a MongoDB GridFS database with a whole range of file types (e.g., text, pdf, xls), and I want to backup this database the easiest way.
Replication is not an […]
- MongoDB GridFs with C#, how to store files such as images? I'm developing a web app with mongodb as my back-end. I'd like to have users upload pictures to their profiles like a linked-in profile pic. I'm using an aspx page with MVC2 and I read […]
- Delete multiple files in MongoDB GridFS in PHP I am using MongoDB and GridFS in PHP, and trying to figure out how to delete multiple files by the _id.
Here is the code I have:
$ids = array("50401f40ff558cec38000061", […]
- Sails.js checking stuff before uploading files to MongoDB with skipper (valid files, image resizing etc) I'm currently creating a file upload system in my application. My backend is Sails.js (10.4), which serves as an API for my separate front-end (Angular).
I've chosen to store the files […]