When I create an index on a collection, one of the properties of the result document is createCollectionAutomatically:false.
db.myCollection.createIndex({"address":1})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1
}
What does it mean and when is this true?
Found the answer here: https://docs.mongodb.com/manual/reference/command/createIndexes/#output
The
createdCollectionAutomaticallyindicates if the operation created a collection. If a collection does not exist, MongoDB creates the collection as part of the indexing operation.
So when I run db.myCollection.createIndex({"address":1}) and myCollection does not exists, the result is
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With