Web2py访问控制& MongoDB的

时间:2014-12-31 21:07:50

标签: mongodb web2py

我正在使用MongoDB作为我的数据库。

db = DAL('mongodb://localhost:27017/app')

当我尝试注册新用户时,出现以下错误:

Traceback (most recent call last):
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/restricted.py", line 209, in restricted
    exec ccode in environment
  File "/home/ecosystem/web2py/applications/app/controllers/default.py", line 146, in <module>
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/globals.py", line 187, in <lambda>
    self._caller = lambda f: f()
  File "/home/ecosystem/web2py/applications/app/controllers/default.py", line 108, in user
    return dict(form=auth())
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/tools.py", line 1205, in __call__
    return getattr(self,args[0])()
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/tools.py", line 2180, in register
    self.add_membership(group_id, form.vars.id)
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/tools.py", line 2963, in add_membership
    record = membership(user_id = user_id,group_id = group_id)
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/dal.py", line 7656, in __call__
    else:
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/dal.py", line 8787, in select
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/dal.py", line 5092, in select
    row=[]
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/pymongo/cursor.py", line 1058, in next
    if len(self.__data) or self._refresh():
  File "/home/ecosystem/anaconda/lib/python2.7/site-packages/pymongo/cursor.py", line 1002, in _refresh
    self.__uuid_subtype))
OverflowError: MongoDB can only handle up to 8-byte ints

如果我查看我的数据库表,除了几个字段外,一切似乎都没问题。

在auth_user中(不确定这个):

registration_id:""

在auth_event中(我假设这不应该为null):

user_id:null

解决此问题的最佳方法是什么?如果可能的话,我想将MongoDB用于所有数据库事务(包括访问控制/身份验证)。

1 个答案:

答案 0 :(得分:0)

更新:您可以通过升级到最新版本的Web2py来避免这种情况。现在完全支持此功能,因此您不需要使用两个不同的数据库。


我无法直接解决这个问题,但我能够创建一个解决方法。在db.py中,我定义了两个单独的数据库连接:

db = DAL('sqlite://storage.sqlite',pool_size=1,check_reserved=['all'])
db1 = DAL('mongodb://localhost:27017/collection')

我在所有auth函数上调用db(最终是一个mysql数据库)(注册,登录,登录检查),同时处理mongo中的所有其他内容(包括详细的成员配置文件)。我经常使用pymongo API完全绕过db1 DAL。