Databases Reference
In-Depth Information
“ns” : “mydb.ratings”,
“key” : {
“_id” : 1
}
},
{
“_id” : ObjectId(“4d02ef30e63c3e677005636f”),
“ns” : “mydb.ratings”,
“key” : {
“movie_id” : -1
},
“name” : “movie_id_-1”
},
{
“_id” : ObjectId(“4d032faee63c3e6770056370”),
“ns” : “mydb.ratings”,
“key” : {
“movie_id” : 1
},
“name” : “movie_id_1”
}
]
You have already created an index on movie_id using a descending order sort using the
following command:
db.ratings.ensureIndex({ movie_id:-1 });
Available for
download on
Wrox.com
movielens_indexes.txt
If required, you could force a query to use a particular index using the hint method. To force
the descending order index on movie_id to get ratings related to “Toy Story (1995)” you can query
as follows:
db.ratings.find({ movie_id:1 }).hint({ movie_id:-1 });
Available for
download on
Wrox.com
movielens_indexes.txt
Soon after running this query, you can verify the query plan to see which index was used and how
it performed. A query plan for the last query using the descending order index on movie_id can be
accessed as follows:
db.ratings.find({ movie_id:1 }).hint({ movie_id:-1 }).explain();
Available for
download on
Wrox.com
movielens_indexes.txt
Search WWH ::




Custom Search