MONGO executing crud on the command line

Source: Internet
Author: User

Use MONGO's own shell command at the command line to perform CRUD operations

First link to database

Increase

Db.qiao.insert ({"QQ": 1})

Db.qiao.save ({"QQ": 3})

Db.qiao.save ({"_id": ObjectId ("5721461f5b4e77bbbae66982"), "QQ": 100})

The difference between save and insert

Insert can only insert data, but it can insert data from a list

Save if you have this data in the database to perform the modification operation, if you do not have this data to perform the insert operation

Insert efficiency is higher than save

By deleting

Db.qiao.remove ({"QQ": 3}) Delete data based on criteria

Db.qiao.remove () Removes the entire document, but does not delete the structure of the document

Db.qiao.drop () Delete the entire database, this data is very fast (but it needs to be re-indexed after deletion)

Delete Data is permanent, cannot be undone, and cannot be recovered.

Change

Db.cs.update ({"_id": ObjectId ("571F46E0A7B78ABFA1768EBF")},{z:20}) The simplest modification, before the number is the search parameters, after the modification parameters

Db.cs.update ({"_id": ObjectId ("571F46E0A7B78ABFA1768EBF")},{"$inc": {"Z": 1}})

$inc Z plus 1 This can be used to do statistical things, or the birthday of the time to execute such a command let the age plus a

Db.cs.update ({"_id": ObjectId ("571F46E0A7B78ABFA1768EBF")},{"$set": {"book": "C # Daquan"}})

$SET Specifies the value of a field. If this field does not exist, create it.

Check

Db.cs.find () returns 10 data at a time in the shell

Db.cs.findOne () returns a single piece of data

Db.cs.find ({"Z": 20}) returns data based on query criteria

MONGO executing crud on the command line

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.