MongoDB Learning Small Notes

Source: Internet
Author: User
Tags modifier

1, configuration: Mongod--dbpath=d:\mongodb\data
Mongo
2, basic additions and deletions to check and change
Find () Update ()--Overall update, local update.
Modifier: $inc db.person.update ({"Age": 23},{$inc: {"Salary": 1000}})
The first parameter is a condition. The second parameter is a modified value, but the value must be an integer. ($inc allowed for numbers only)
$set modifier: db.person.update ({"Name": "Gll"},{$set: {"Age": 25}}
There is also an action to modify or add an action: This can be called insertorupdate operation.
Just set the third parameter of update to TRUE. If not, just add a new one in the database to avoid the database to determine whether the update or add operation. Easy to use.
Batch update:
If you match more than one, only the first one is updated by default. If more than one update is required, set it to true in the fourth parameter of update. Also very simple.
Remove operation.
3. Advanced operation
Polymerization:
Count () distinct () which property is selected and which cannot be duplicated.
Group () parameter key: Specifies the basis for grouping documents, all the values of age keys are divided into a set, and true is the value of the return key age.
Initial: "initial": {"person": []} The initial number of each set of reduce function calls, all members of the first group will use this accumulator.
Plainly. This is an initial value. Each time $reduce calls this value to change the value.
Example:

Db.person.Group({. "Key": {" Age ": true},." Initial ": {" person ":[]},. "$reduce":function(Cur,prev) {The first parameter is the current document and the second parameter is an accumulator document. Prev.person.push (Cur.name);. }. }) Eg:db.person.Group({"Key": {" Age ": true}," initial ": {' person ':[]}, "$reduce":function(doc,out) {Out.person.push (doc.name);}, "Finalize":function{out] {out.Count=out.person.length;}, "condition": {"age": {$lt: -}}


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.