使用 django-mongodb,如何对上限集合进行降序排序?
有这个模型,一个表示 mongodb 上的上限集合的类:
class Event(models.Model):
objects = MongoDBManager()
create_at = models.DateTimeField(auto_now_add=True)
obj = BlobField()
class MongoMeta:
capped = True
collection_size = 1000*1024*1024
我可以使用什么来按照插入的相反顺序获取文档?
Have this model, a class representing a capped collection at mongodb:
class Event(models.Model):
objects = MongoDBManager()
create_at = models.DateTimeField(auto_now_add=True)
obj = BlobField()
class MongoMeta:
capped = True
collection_size = 1000*1024*1024
What can I use to get the documents in the reverse order they are inserted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
master
分支a> 获取工作版本。master
branch of our Git repository to get the working version.这是 pymongo 级别的临时解决方案,不是 django-mongodb 级别:
This is a temporal solution at pymongo level, not django-mongodb level:
我不是一个Python人,但我可以告诉你上限集合自然顺序< /a> 是插入顺序。因此,您可以执行与此等效的 python 操作来获得相反的顺序:
一些谷歌搜索告诉我这在 python 中转换为类似以下内容:
或者:
I am not a python person but I can tell you that capped collections Natural Order is the order of insertion. Therefore you can just do the python equivalent of this to get the reverse order:
A bit of googling tells me this translates to something like the following in python:
Or: