[DB] MongoDB access and modification for simple small instances

Source: Internet
Author: User

1. 100 entries are generated

VaR A = new array (100); // There Is. foreach. I don't know why I can only use for (VAR I = 0; I <. length; I ++) {dB. test. insert ({X: I})} // who knows how to write in the JS shell provided by Mongo?CodeLine feed

Using dB. Test. Find (), you can see that the database has been imported into the database. Enter the it command to view more information on the page.

2. Add 1 to the data that can be modeled by 2.

> Var cursor = dB. test. find ();> cursor. foreach (function (m) {M. X % 2 & (dB. test. update ({X: M. X },{ $ Inc {X: 1}); print (M. x )})

Create a cursor and use the cursor iterator foreach provided by Mongo to perform operations.

3. Use dB. Test. Find () to check the results. You can see that the database has been updated.

 

PS:

Code line feed

For () {// press ENTER

... // Will appear...

...} // Press ENTER

Will be executed

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.