1 Viewing the documentation for the current database
Input:
Db.media.find ()
System returns:
{"_id": ObjectId ("5aa490f053350e04ddbd6fa6"), "Type": "Book", "Title": "Definitive Guide to MongoDB 3rd ed.", "ISBN": "978-1-4842-1183-0", "Publisher": "Apress", "Author": ["Hows,david", "Plugge,eelco", "Membrey,peter", "Hawkins,tim"] }
{"_id": ObjectId ("5aa4912953350e04ddbd6fa7"), "Type": "CD", "Artist": "Nirvana", "Title": "Nevermind", "tracklist": [{' track ': ' 1 ', ' title ': ' Smells like Teen Spirit ', ' Length ': ' 5:02 '}, {' track ': ' 2 ', ' title ': ' In Bloom ', ' lengt H ":" 4:15 "}]}
{"_id": ObjectId ("5aa4915453350e04ddbd6fa8"), "Type": "Book", "Title": "Definitive Guide to MongoDB 3rd ed.", "ISBN": "978-1-4842-1183-1", "Publisher": "Apress", "Author": ["Hows,david", "Plugge,eelco", "Membrey,peter", "Hawkins,tim"] }
2 Get unique values using the distinct () function
Db.media.distinct ("Title")
System returns:
["Definitive Guide to MongoDB 3rd ed.", "Nevermind"]
3 using group () grouping
Db.media.group ({key:{title:true},initial:{total:0},reduce:function (Items,prev) {prev. Total + = 1}})
System returns:
[
{
"Title": "Definitive Guide to MongoDB 3rd ed.",
"Total": 2
},
{
"Title": "Nevermind",
"Total": 1
}
]
MongoDB simple to use-query operation 2