MongoDB Learning (iv)

Source: Internet
Author: User
Tags create index mongodb mongodb limit mongodb projection

One, Mongodb projection

Projection means that you select only the data for the field you want, rather than selecting the data for the entire document field. (That is, return the specified field)

The second parameter of the Find method is the Set field display parameter 1 shows the current field 0 hides the current field

Find ({},{key:1})

Two, MongoDB limit record number

Limit (number) returns the number bar data

Skip (number) Skips the result of the query to the number bar data returned

Third, MongoDB sort

Sort ({key:1}) sorted ascending by key field 1 Ascending-1 descending

Iv. MongoDB Set Index

Improve query efficiency, you can create a single index to create a composite index

Key: Name of the field that created the index 1 ascending-1 Creating an index in descending order

Ensureindex ({key:1},{unique:true}) CREATE index

Background: Create an index in the background. So that building an index does not prevent other database activities

Unique: Create a unique index

Name: Index names

Five, MongoDB aggregation query

Aggregate ()

$sum summation

$avg mean value

$min Minimum value
$max Maximum Value
$push adding values to the array can be repeated
$addToSet adds a value to the array, but does not create duplicates



MongoDB Learning (iv)

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.