wxh:PRIMARY> db.coll.stats()
{
"ns" : "test.coll",
"count" : 4,
"size" : 144,
"avgObjSize" : 36,
"storageSize" : 4096,
"numExtents" : 1,
"nindexes" : 3,
"lastExtentSize" : 4096,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 24528,
"indexSizes" : {
"_id_" : 8176,
"id2_1" : 8176,
"x_1" : 8176
},
"ok" : 1
}
wxh:PRIMARY> db.coll.ensureIndex({x:1} ,{unique:true})
wxh:PRIMARY> db.coll.ensureIndex({x:1} ,{unique:true});db.runCommand({getLastError : 1})
{
"n" : 0,
"lastOp" : Timestamp(1390440428, 1),
"connectionId" : 86,
"err" : null,
"ok" : 1
}
wxh:PRIMARY> db.oplog.rs.find().sort({$natural:-1}).limit(2)
{ "ts" : Timestamp(1390440428, 1), "h" : NumberLong("-5546458038095236090"), "v" : 2, "op" : "i", "ns" : "test.system.indexes", "o" : { "_id" : ObjectId("52e06fec385d871d833ea696"), "ns" : "test.coll", "key" : { "x" : 1 }, "name" : "x_1", "unique" : true } }
{ "ts" : Timestamp(1390440384, 1), "h" : NumberLong("1177839887768694332"), "v" : 2, "op" : "i", "ns" : "test.system.indexes", "o" : { "_id" : ObjectId("52e06fc0385d871d833ea695"), "ns" : "test.coll", "key" : { "x" : 1 }, "name" : "x_1", "unique" : true } }
MONGODB重复在已经存在索引的列上建立索引不报错,而且OPLOG里也会把这个操作记录进去,但是其实后台发现这个列上已经存在索引,并不会真正的去创建。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22034023/viewspace-1074361/
,如需转载,请注明出处,否则将追究法律责任。