MongoDB Upgrade Tutorial

Source: Internet
Author: User
Tags mongodump mongorestore

1. Sorting

Sort () Method: where 1 is in ascending order, and 1 is for descending order.

DB. Col. Find({},{"title":1,_id:0}). Sort({"likes":-1})

If you do not specify how the sort () method is sorted, the default is in ascending order of the document.

2. Index

The Ensureindex () method to create the index.

DB. Col. Ensureindex({"title":1})

1 Create an index in ascending order for the specified-1 to create an index in descending order

You can also set the index to be created using multiple fields

DB. Col. Ensureindex({"title":1,"description":-1})

Methods are mainly acceptable parameters:

3. Polymerization Piping

Aggregations (aggregate) are primarily used to process data (such as statistical averages, sums, etc.) and return the computed data results. A bit like the count (*) in the SQL statement.

Similar to SQL statement: Select By_user, COUNT (*) from MyCol GROUP by By_user

DB. MyCol. Aggregate([{$group : {_id : "$by _user", num_tutorial : { $sum : 1}}])

Aggregation Common Expressions:

Pipeline

Several common operations in the aggregation framework:

    • $project: Modifies the structure of the input document. You can use it to rename, add, or delete fields, or to create calculations and nested documents.
    • $match: Used to filter data and only output documents that match the criteria. $match a standard query operation using MONGODB.
    • $limit: Used to limit the number of documents returned by the MongoDB aggregation pipeline.
    • $skip: Skips the specified number of documents in the aggregation pipeline and returns the remaining documents.
    • $unwind: Splits one of the array type fields in the document into multiple bars, each containing a value in the array.
    • $group: Groups The documents in the collection to be used for statistical results.
    • $sort: Sorts the input documents after the output.
    • $geoNear: Outputs an ordered document that is close to a geographic location.

4. Copy

MongoDB replication is the process of synchronizing data across multiple servers.

Replication provides redundant backups of data, stores copies of data on multiple servers, improves data availability, and guarantees data security.

Replication also allows you to recover data from hardware failures and service outages.

MongoDB requires a minimum of two nodes for replication.

One is the master node, which handles client requests,

The rest is from the node, which is responsible for replicating the data on the master node.

MongoDB Replica Set settings

5. sharding

In MongoDB there is another cluster, that is, the Shard technology, can meet the requirements of a large number of MONGODB data volume growth.

6. Backup and Recovery

Mongodump

Mongodump -H dbhost -D dbname -o dbdirectory

Mongorestore

Mongorestore -H dbhost -D dbname --directoryperdb dbdirectory

MongoDB Upgrade Tutorial

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.