【问题标题】:Pymongo array field: Guaranteed to have its elements stay in the orderPymongo 数组字段:保证其元素保持有序
【发布时间】:2018-02-02 19:07:30
【问题描述】:

Python 确保列表元素保持有序。

据我了解,MongoDB 数组也保持数组的顺序。

使用 Pymongo 也能保证插入、检索和更新时的顺序一致?

我没有很大的理由怀疑这一点,但我找不到任何关于它的参考!

pymongo==3.3.1

MongoDB 3.4.9

谢谢!

【问题讨论】:

    标签: pymongo


    【解决方案1】:

    https://api.mongodb.com/python/current/api/bson/index.html 提供 python 类型到 BSON 类型的映射。由于双方都保持顺序,因此插入,检索等应该保持顺序。

    由于python dicts不维护key order,BSON包还提供http://api.mongodb.com/python/current/api/bson/son.html 如果数组顺序没有得到维护,他们可能也会提供一些工具来处理它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 2022-12-11
      • 2015-11-02
      相关资源
      最近更新 更多