【问题标题】:How do you specify the order of the shard key fields in pymongo? (for mongodb)您如何指定 pymongo 中的分片键字段的顺序? (对于 MongoDB)
【发布时间】:2012-02-12 03:31:45
【问题描述】:

pymongo 中如何指定分片键字段的顺序? (对于 mongodb)

基本上,pymongo 允许你这样做:

connection.admin.command('shardcollection', 'dbname.collname', key = {c:1,b:1,a:1})

但这不尊重我的钥匙的顺序。

如果您在 mongo shell 中执行此操作,它会尊重键的顺序。

有人知道如何在pymongo中指定顺序吗?

非常感谢您的帮助。

【问题讨论】:

    标签: mongodb pymongo


    【解决方案1】:

    我想通了!

    from collections import OrderedDict
    
    key = OrderedDict([('a',1), ('b', 1), ('c',1)])
    ...
    ...
    connection.admin.command('shardcollection', 'mydb.test', key=key)
    

    【讨论】:

    • 哎呀!我没有看到你发布答案。顺便说一句,它不适合我。它说“缺失值”。有什么想法吗?
    • 尝试一个元组列表,例如 [('c', 1), ('b', 1), ('a', 1) ]
    猜你喜欢
    • 1970-01-01
    • 2018-03-15
    • 2020-07-23
    • 2012-07-14
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多