Mongokit - 查找最后添加的记录

发布于 2024-11-15 06:00:37 字数 1705 浏览 4 评论 0原文

将 Mongokit 与 Python 结合使用。获取最后 n 条记录时遇到一些困难。不确定Python在这里到底想要什么语法,但我有:

record = collection.find(sort = [{'timestamp': DESCENDING}],limit=10)

这给了我错误:

Traceback (most recent call last):
  File "C:\Python26\lib\site-packages\flask-0.6-py2.6.egg\flask\app.py", line 874, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Python26\lib\site-packages\flask-0.6-py2.6.egg\flask\app.py", line 864, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "C:\Python26\lib\site-packages\flask-0.6-py2.6.egg\flask\app.py", line 861, in wsgi_app
    rv = self.dispatch_request()
  File "C:\Python26\lib\site-packages\flask-0.6-py2.6.egg\flask\app.py", line 696, in dispatch_reque
st
    return self.view_functions[rule.endpoint](**req.view_args)
  File "E:\My Dropbox\Cranktrain\Blog\crankblog\apps\admin\views.py", line 24, in panel
    record = collection.find(sort = [{'timestamp': DESCENDING}],limit=10)
  File "C:\Python26\lib\site-packages\mongokit-0.5.13.1-py2.6.egg\mongokit\collection.py", line 67,
in find
    return Cursor(self, *args, **kwargs)
  File "C:\Python26\lib\site-packages\mongokit-0.5.13.1-py2.6.egg\mongokit\cursor.py", line 35, in _
_init__
    super(Cursor, self).__init__(*args, **kwargs)
  File "C:\Python26\lib\site-packages\pymongo-1.9-py2.6-win32.egg\pymongo\cursor.py", line 95, in __
init__
    self.__ordering = sort and helpers._index_document(sort) or None
  File "C:\Python26\lib\site-packages\pymongo-1.9-py2.6-win32.egg\pymongo\helpers.py", line 65, in _
index_document
    for (key, value) in index_list:
ValueError: need more than 1 value to unpack

任何帮助都会很棒。

Using Mongokit with Python. Having some trouble working out get the last n number of records. Not sure of the syntax Python wants here exactly, but I have:

record = collection.find(sort = [{'timestamp': DESCENDING}],limit=10)

Which gives me the error:

Traceback (most recent call last):
  File "C:\Python26\lib\site-packages\flask-0.6-py2.6.egg\flask\app.py", line 874, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Python26\lib\site-packages\flask-0.6-py2.6.egg\flask\app.py", line 864, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "C:\Python26\lib\site-packages\flask-0.6-py2.6.egg\flask\app.py", line 861, in wsgi_app
    rv = self.dispatch_request()
  File "C:\Python26\lib\site-packages\flask-0.6-py2.6.egg\flask\app.py", line 696, in dispatch_reque
st
    return self.view_functions[rule.endpoint](**req.view_args)
  File "E:\My Dropbox\Cranktrain\Blog\crankblog\apps\admin\views.py", line 24, in panel
    record = collection.find(sort = [{'timestamp': DESCENDING}],limit=10)
  File "C:\Python26\lib\site-packages\mongokit-0.5.13.1-py2.6.egg\mongokit\collection.py", line 67,
in find
    return Cursor(self, *args, **kwargs)
  File "C:\Python26\lib\site-packages\mongokit-0.5.13.1-py2.6.egg\mongokit\cursor.py", line 35, in _
_init__
    super(Cursor, self).__init__(*args, **kwargs)
  File "C:\Python26\lib\site-packages\pymongo-1.9-py2.6-win32.egg\pymongo\cursor.py", line 95, in __
init__
    self.__ordering = sort and helpers._index_document(sort) or None
  File "C:\Python26\lib\site-packages\pymongo-1.9-py2.6-win32.egg\pymongo\helpers.py", line 65, in _
index_document
    for (key, value) in index_list:
ValueError: need more than 1 value to unpack

Any help would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单调的奢华 2024-11-22 06:00:37

您应该给它一个 [(field, Direction), ...] 列表,而不是字典。

必须订购分选规格;字典没有排序。

不确定您是否需要使用列表,请尝试仅 (field, Direction)

You should give it a [(field, direction), ...] list, not a dict.

Sorting specifications must necessarily be ordered; dicts are not ordered.

Not sure that you need to use a list, try just (field, direction).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文