I’m trying to understand my database indexing. When starting, my server runs:
Videos._ensureIndex(
{
_id: 1,
owner_id: 1,
ts: 1,
likesCount: 1,
repostsCount: 1,
published: 1,
isPrivate: 1,
readyToPlay: 1,
order: 1,
favoritesCount: 1,
deleted: 1,
isSlice: 1,
},
{
name: 'videoIndex',
}
);
When I connect to my mongo shell and run db.videos.getIndexes()
I get:
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "pie.videos"
},
{
"v" : 1,
"key" : {
"_id" : 1,
"owner_id" : 1,
"ts" : 1,
"likesCount" : 1,
"repostsCount" : 1
},
"name" : "_id_1_owner_id_1_ts_1_likesCount_1_repostsCount_1",
"ns" : "pie.videos",
"background" : true
},
{
"v" : 1,
"key" : {
"_id" : 1,
"owner_id" : 1,
"ts" : 1,
"likesCount" : 1,
"repostsCount" : 1,
"published" : 1,
"isPrivate" : 1,
"readyToPlay" : 1,
"order" : 1
},
"name" : "_id_1_owner_id_1_ts_1_likesCount_1_repostsCount_1_published_1_isPrivate_1_readyToPlay_1_order_1",
"ns" : "pie.videos",
"background" : true
},
{
"v" : 1,
"key" : {
"_id" : 1,
"owner_id" : 1,
"ts" : 1,
"likesCount" : 1,
"repostsCount" : 1,
"published" : 1,
"isPrivate" : 1,
"readyToPlay" : 1,
"order" : 1,
"featuredScore" : 1
},
"name" : "_id_1_owner_id_1_ts_1_likesCount_1_repostsCount_1_published_1_isPrivate_1_readyToPlay_1_order_1_featuredScore_1",
"ns" : "pie.videos",
"background" : true
},
{
"v" : 1,
"key" : {
"_id" : 1,
"owner_id" : 1,
"ts" : 1,
"likesCount" : 1,
"repostsCount" : 1,
"published" : 1,
"processingComplete" : 1
},
"name" : "_id_1_owner_id_1_ts_1_likesCount_1_repostsCount_1_published_1_processingComplete_1",
"ns" : "pie.videos",
"background" : true
},
{
"v" : 1,
"key" : {
"_id" : 1,
"owner_id" : 1,
"ts" : 1,
"likesCount" : 1,
"repostsCount" : 1,
"published" : 1,
"readyToPlay" : 1
},
"name" : "_id_1_owner_id_1_ts_1_likesCount_1_repostsCount_1_published_1_readyToPlay_1",
"ns" : "pie.videos",
"background" : true
},
{
"v" : 1,
"key" : {
"_id" : 1,
"owner_id" : 1,
"ts" : 1,
"likesCount" : 1,
"repostsCount" : 1,
"published" : 1,
"readyToPlay" : 1,
"order" : 1
},
"name" : "_id_1_owner_id_1_ts_1_likesCount_1_repostsCount_1_published_1_readyToPlay_1_order_1",
"ns" : "pie.videos",
"background" : true
},
{
"v" : 1,
"key" : {
"owner_id" : 1,
"ts" : 1
},
"name" : "owner_id_1_ts_1",
"ns" : "pie.videos",
"background" : true
},
{
"v" : 1,
"key" : {
"_id" : 1,
"owner_id" : 1,
"ts" : 1,
"likesCount" : 1,
"repostsCount" : 1,
"published" : 1,
"isPrivate" : 1,
"readyToPlay" : 1,
"order" : 1,
"featuredScore" : 1,
"deleted" : 1
},
"name" : "videoIndex",
"ns" : "pie.videos"
}
]
I’m trying to understand what that means. I was expecting an index per field I’m asking for, but I’m getting a number of indexes that each concerns a group of fields. I’m not sure why that is.
I’ve sometimes changed the fields I’m asking for in _ensureIndex
so I’m wondering if each time I changed that this added a new group, or if this is the expected form of my index, and if so what that means exactly.