_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 }

 

 

相关文章:

  • 2021-09-21
  • 2021-10-21
  • 2022-12-23
  • 2021-05-06
  • 2021-06-12
  • 2021-06-26
  • 2021-05-26
  • 2022-02-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2021-10-28
  • 2021-11-30
  • 2021-12-07
相关资源
相似解决方案