索引 _id

_id索引是绝大多数集合默认建立的索引,对于每个插入的数据,mongodb都会自动生成一条唯一的_id字段
增加一个数据
> db.test2.insert({x:1})
WriteResult({ "nInserted" : 1 })
> db.test2.getIndexes()
[
    {
        "v" : 2,
        "key" : {
            "_id" : 1
        },
        "name" : "_id_",
        "ns" : "config.test2"
    }
]
可以看到默认添加了_id索引
> db.test2.find()
{ "_id" : ObjectId("5b60e31524326393d99a4f64"), "x" : 1 }
原文地址:https://www.cnblogs.com/wzndkj/p/9399199.html