django / mongodb / manage dbshell

django / mongodb / manage dbshell

  • Written by
    Walter Doekes
  • Published on

The current django-mongodb-engine doesn’t seem to ship with a working manage dbshell command yet. Right now it returns this:

$ ./manage.py dbshell
...
  File "/home/walter/.virtualenvs/myproject/lib/python2.6/site-packages/django/core/management/commands/dbshell.py", line 21, in handle
    connection.client.runshell()
  File "/home/walter/.virtualenvs/myproject/lib/python2.6/site-packages/django_mongodb_engine/base.py", line 108, in __getattr__
    raise AttributeError(attr)
AttributeError: client

The fix is simple, patch your django_mongodb_engine with this:

--- django_mongodb_engine/base.py.orig  2011-11-15 11:53:47.000000000 +0100
+++ django_mongodb_engine/base.py 2011-11-15 11:54:07.000000000 +0100
@@ -7,6 +7,7 @@
 from pymongo.connection import Connection
 from pymongo.collection import Collection

+from .client import DatabaseClient
 from .creation import DatabaseCreation
 from .utils import CollectionDebugWrapper

@@ -87,6 +88,7 @@
         self.features = DatabaseFeatures(self)
         self.ops = DatabaseOperations(self)
         self.creation = DatabaseCreation(self)
+        self.client = DatabaseClient(self)
         self.introspection = DatabaseIntrospection(self)
         self.validation = DatabaseValidation(self)
         self.connected = False
--- /dev/null 2011-10-04 03:15:41.939918405 +0200
+++ django_mongodb_engine/client.py 2011-11-15 11:52:13.000000000 +0100
@@ -0,0 +1,15 @@
+import os
+import sys
+
+from django.db.backends import BaseDatabaseClient
+
+class DatabaseClient(BaseDatabaseClient):
+    executable_name = 'mongo'
+
+    def runshell(self):
+        settings_dict = self.connection.settings_dict
+        args = [self.executable_name, settings_dict['NAME']]
+        if os.name == 'nt':
+            sys.exit(os.system(" ".join(args)))
+        else:
+            os.execvp(self.executable_name, args)

This was tested with django 1.3 (wkornewald nonrel) and django-mongodb-engine 0.4.0.


Back to overview Newer post: fixing symptoms / not problems Older post: certificate verify fail / crt / bundle