【问题标题】:What does the digit "1" mean when creating indexes in mongodb在mongodb中创建索引时数字“1”是什么意思
【发布时间】:2014-11-13 11:53:32
【问题描述】:

我是 mongodb 的新手,想为特定的集合创建索引。我见过人们在创建索引时在字段名称前使用数字“1”。例如:

db.users.ensureIndex({user_name: 1})

现在我想知道这个数字是什么意思,有必要用吗?

【问题讨论】:

    标签: mongodb indexing nosql


    【解决方案1】:

    这是索引的类型。 MongoDB 支持不同类型的索引。但是,只有前两个索引可以组合成compound index

    如需更多信息,请参阅the documentation of index types

    【讨论】:

      【解决方案2】:

      它定义了该特定字段的索引类型。例如,值 1 创建一个升序索引,而值 -1 创建一个降序索引。

      有关详细信息,请参阅Manual

      【讨论】:

      • 感谢您的回答!
      • 还有可能的值"hashed""text""2d""2dshphere"
      猜你喜欢
      • 1970-01-01
      • 2010-12-28
      • 2018-10-10
      • 2022-01-11
      • 2022-11-25
      • 2021-05-30
      • 2012-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多