AttributeError:'module'对象没有属性'code'

时间:2012-05-28 10:02:41

标签: python mongodb pymongo mongoengine

我正在编写一个像这样的MongoDB查询:     Message.objects.filter(Q(author_id = user.id)| Q(for_user_id = user.id)| Q(shared_with_id = user.id))。order_by(“ - timestamp”)[:10]

版本是

MongoDB = 1.8.2 Pymonogo:1.11

Traceback (most recent call last):

File "/mnt/install/wwm/thirdparty/django/core/handlers/base.py", line 100, in    get_response
response = callback(request, *callback_args, **callback_kwargs)

File "/mnt/install/wwm/thirdparty/django/contrib/auth/decorators.py", line 25, in _wrapped_view
return view_func(request, *args, **kwargs)

 File "/mnt/install/wwm/main/views.py", line 1232, in user_messages
 mesg_list = list(Message.objects( Q(author_id=user.id) | Q(for_user_id=user.id) | Q( shared_with_id=user.id)).order_by( "-timestamp")[:10])

 File "/mnt/install/wwm/thirdparty/mongoengine/queryset.py", line 223, in call
 self._where_clause = q_obj.as_js(self._document)

  File "/mnt/install/wwm/thirdparty/mongoengine/queryset.py", line 89, in as_js
  return pymongo.code.Code(' '.join(js), js_scope)

 AttributeError: 'module' object has no attribute 'code'

同样的代码行正常工作 pymongo:2.0.1 mongodb:2.1.0

你能说出确切的错误或任何解决方法,因为我不想更新pymongo。

由于

1 个答案:

答案 0 :(得分:2)

正如github上提到的那样:

  

不再支持Pymongo 1.11。我建议更新   pymongo如果可能的话。如果不可能,您需要查看导入   由于代码和其他人已被转移到bson模块。

您使用的是什么版本的MongoEngine?