mongodb 添加索引

填写索引必须在主节点中进行

查看主节点执行db.serverStatus();命令,找到返回结果中的primary对应的IP就是master

"repl" : {
        "hosts" : [ 
            "10.0.11.28:27017", 
            "10.0.11.30:27017", 
            "10.0.11.29:27017"
        ],
        "primary" : "10.0.11.28:27017"

}

在主节点中执行

db.集合名称.createIndex({"字段1":1,"字段2":-1}) // 1为升序 -1为将序

 

转载于:https://my.oschina.net/kdy1994/blog/3079550

你可能感兴趣的:(mongodb 添加索引)