MongoDB Learning Notes _mongodb

Source: Internet
Author: User
Tags modifier mongodb prev

1, configuration: Mongod--dbpath=d:\mongodb\data

Mongo

2, the 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 argument is a condition. The second parameter is the modified value, but the value must be an integer. ($inc allowed for numbers only)

$set modifier: db.person.update ({"Name": "Gll"},{$set: {"Age": 25}}}

Another action is to modify or add an operation: This can be called a 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 more than one match is matched, only the first article is updated by default. If more than one update is required, set the fourth parameter in update to TRUE. is also very simple.

Remove operation.

3. Advanced operation

Polymerization:

Count () distinct () which property is selected, which cannot be duplicated.

Group () parameter key: Specifies the basis on which the document is grouped, the values of all age keys are divided into one group, and true to return the value of the key age.

Initial: "initial": {"person": []} The initial number of reduce function calls per group, all members of the first group will use this accumulator.

Plainly. This is an initial value. This value is invoked at each $reduce to change the value.

Example:

Db.person.group ({
. ' key ': {' age ': true},
. "Initial": {"person": []},
. $reduce: Function (Cur,prev) {The first argument is the current document, and the second parameter is the 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.