How do I index a database column

后端 未结 9 1855
难免孤独
难免孤独 2020-12-12 15:51

Hopefully, I can get answers for each database server.

For an outline of how indexing works check out: How does database indexing work?

9条回答
  •  抹茶落季
    2020-12-12 16:00

    Since most of the answers are given for SQL databases, I am writing this for NOSQL databases, specifically for MongoDB.

    Below is the syntax to create an index in the MongoDB using mongo shell.

    db.collection.createIndex( ,  )
    

    example - db.collection.createIndex( { name: -1 } )

    In the above example an single key descending index is created on the name field.

    Keep in mind MongoDB indexes uses B-tree data structure.

    There are multiple types of indexes we can create in mongodb, for more information refer to below link - https://docs.mongodb.com/manual/indexes/

提交回复
热议问题