0

As stated in the title, I am using django-mongodb-engine and I am attempting to configure the native Django authentication framework. I've read some comments online that it should work out of the box sans some features. However, I couldn't find any tutorials and, furthermore, I am getting errors on trying to set it up on my own. The issue I'm having most certainly has to do with database permissions. I have included the Django middleware and apps per the Django docs. However, when I issue the syncdb command it fails with an error.

$ python manage.py syncdb
OperationFailure: database error: not authorized for query on MyDB.system.namespaces

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django_mongodb_engine',
        'NAME': 'MyDB',
        'USER': 'mySuperUser',
        'PASSWORD': 'mypass',
        'HOST': 'XXX.XXX.XXX.XXX',
        'PORT': '',
    },
    # some other DBs
}

Mongo User Permissions

myDB> db.system.users.find()
{ "_id" : ObjectId("..."), "user" : "mySuperUser", "pwd" : "...", "roles" : [   "readWriteAnyDatabase", "userAdminAnyDatabase",         "dbAdminAnyDatabase",   "clusterAdmin" ] }

I'm not sure what other permissions I can grant this guy, and/or where else I need to create this user.

Any ideas?

4

3 回答 3

0

我的问题是我没有在我的 settings.py 中指定 SITE_ID。我这样做了:

./manage.py shell
>>>from django.contrib.sites.models import Site
>>>Site().save()
>>>Site.objects.all()[0].id
u'5391dbc22ebd1212246d50c4'

如果您不是“django.contrib.sites”,那么我不确定为什么会出现问题。除非您一直在使用该模块并且已经将集合/表安装到数据库中。无论哪种情况,这都是我让 MongoDB 重新开始正常工作的方式。

于 2014-06-06T15:26:38.843 回答
0

玩了之后,这里是解决方案。您必须使用本机 mongoadmin数据库。因此,所需的更改:

# settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django_mongodb_engine',
        'NAME': 'admin',
        'USER': 'mySuperUser',
        'PASSWORD': 'mypass',
        'HOST': 'XXX.XXX.XXX.XXX',
        'PORT': '',
    },
    # some other DBs
}

用户mySuperUser必须自然地存在于admin数据库中。为了安全起见,添加和删除用户等身份验证操作,我userAdminAnyDatabase在 mongo 中赋予了它特权。权限可能过多,但我必须使用它来确定所需权限的适当范围。以下是权限:

// mongo
admin> db.system.users.find()
{ "_id" : ObjectId("..."), "pwd" : "...", "roles" : [         "readWriteAnyDatabase",         "dbAdminAnyDatabase",   "clusterAdmin",         "userAdminAnyDatabase" ], "user" : "mySuperUser" }

接下来,我们终于可以运行syncdb命令了:

$ python manage.py syncdb
Creating tables ...

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'someUser'): 
Email address: someUser@user.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...

Installing indices for admin.LogEntry model.
Installing indices for auth.Group_permissions model.
Installing indices for auth.Group model.
Installing indices for auth.User_groups model.
Installing indices for auth.User_user_permissions model.
Installing indices for auth.User model.
Installing indices for sessions.Session model.
Installed 0 object(s) from 0 fixture(s)
$
于 2014-02-12T17:07:27.210 回答
-1

我遇到了同样的问题。我的 Mongo DB 托管在 MongoLab 上,我没有找到解决此错误的任何解决方案。尽管我的用户已经存在于我的数据库中,但我不想使用该admin数据库。其他人遇到过同样的问题或找到解决方案?

于 2014-03-19T21:33:27.500 回答