MongoDB simple to use-query operation 2

Source: Internet
Author: User
Tags prev

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.