Mongokit - 查找最后添加的记录
将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该给它一个
[(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)
.