填写索引必须在主节点中进行
查看主节点执行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为将序