数据准备:在mongodb命令行终端执行如下代码

for(var i=0;i<100000;i++) {
... db.users.insert({username:"user"+i,age:i})
... }

1. 默认索引

  MongoDB有个默认的“_id”的键,他相当于“主键”的角色。集合创建后系统会自动创建一个索引在“_id”键上,它是默认索引,索引名叫“_id_”,是无法被删除的。我们可以通过以下方式查看:

var _idIndex = mongoCollection.Metadata.Indexes.Single(x => x.Key == "_id_");
Console.WriteLine(_idIndex);
 

相关文章:

  • 2022-12-23
  • 2021-05-23
  • 2021-09-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2021-08-11
  • 2021-08-28
  • 2021-04-07
相关资源
相似解决方案