Indexing in Mongo

Write a mongo query for Indexing in mongo.

Example:

[{ 
    "_id" : ObjectId("6020d98f62864f47ec0e1ca3")
    "mediaSite" : "facebook"
    "date" : ISODate("2021-02-05T18:30:00.000+0000")
    "hourly_View" : {
        "1" : 123.0
        "2" : 323.0
       "24" : 234.0
    }
}
]

Approach

Query: Create index using one field in mongo.

 
db.getCollection("SocialMediaTik").createIndex({"mediaSite":1});

Output: 

[
    "createdCollectionAutomatically" : false
    "numIndexesBefore" : 1.0
    "numIndexesAfter" : 2.0
    "ok" : 1.0
}
]


No comments:

Post a Comment