MongoDB: db.collection.getIndexes() method
db.collection.getIndexes
The db.collection.getIndexes() method is used to return an array that holds a list of documents that identify and describe the existing indexes on a collection.
db.collection.getIndexes()
Syntax:
db.collection.getIndexes()
Sample document in the restaurants collection:
{
"address": {
"building": "1007",
"coord": [ -73.856077, 40.848447 ],
"street": "Morris Park Ave",
"zipcode": "10462"
},
"borough": "Bronx",
"cuisine": "Bakery",
"grades": [
{ "date": { "$date": 1393804800000 }, "grade": "A", "score": 2 },
{ "date": { "$date": 1378857600000 }, "grade": "A", "score": 6 },
{ "date": { "$date": 1358985600000 }, "grade": "A", "score": 10 },
{ "date": { "$date": 1322006400000 }, "grade": "A", "score": 9 },
{ "date": { "$date": 1299715200000 }, "grade": "B", "score": 14 }
],
"name": "Morris Park Bake Shop",
"restaurant_id": "30075445"
}
.......
Example: MongoDB: db.collection.getIndexes() method
Following example describe the indexes on the restaurants database
db.restaurants.getIndexes();
Output:
[ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.restaurants" } ]
Retrieve the restaurants data from here
Previous:
db.collection.findOne() method
Next:
db.collection. getShardDistribution() method
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join