我无法删除 _id 索引,为什么?
当我尝试运行该dropIndexes
命令时,它会删除所有索引,但不会删除 _id 索引。
做'db.runCommand'
也不起作用:
> db.runCommand({dropIndexes:'fs_files',index:{_id:1}})
{ "nIndexesWas" : 2, "errmsg" : "may not delete _id index", "ok" : 0 }
不好。
我可以在复合索引中使用包含 _id 的字段吗?
我在网上找不到任何东西,该ensureindex
命令无法执行。
db.fs_files.ensureIndex({'_id':1, 'created':1});
上面的命令刚刚创建了一个新的复合索引。我还没有找到一些类似的“创建索引”命令。
默认 _id 索引是唯一索引吗?
getIndexes
返回它不是唯一索引。
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "gridfs.fs_files",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"created" : 1
},
"unique" : true,
"ns" : "gridfs.fs_files",
"name" : "created_1"
}