MongoDB Increase and deletion check (a)

Source: Internet
Author: User

This article mainly introduces MongoDB database additions and deletions to check operation.

Increase

MongoDB, like other relational databases, uses insert to add data to the collection.

db.collectionName.insert(内容)

Show all collections in the database:

show collections

Delete

In MongoDB, remove removes documents that meet certain criteria in the collection.
Remove accepts a number of parameters. As a condition to find the document to delete:

Of course, it is also possible to delete an entire collection directly by dropping the method:

db.person.drop()

Deleting a collection and then rebuilding the index is faster than deleting all the documents in the collection.

Change

The change operation is more complex than adding and deleting, since MongoDB is not only able to use the Update method, but also can use a lot of auxiliary churn, we first say the Update method.

Update

The Update method accepts two parameters, the first of which is to find the document's qualifications, and the second new document that needs to be changed:

In the above update ({“name”:”liufang”},post) , the equivalent of the inference condition in the where in the name:liufang relational database, and post is relative to the running content after the SET statement.

The simplest thing to update is to use a new document instead of a matching document, which is suitable for a time when the pattern structure has changed significantly. For example, the following documents:

{  "name":"tyq",  "age":22,  “date”:newDate()}

Change to:

{  "name":"tyq",    “age”:22,    “friends”:”liufang”}

For example, with:

Change Device

Let's talk about MongoDB's powerfulChange Device
MongoDB has some auxiliaryChange Device。 Example inc, Set u n s Span class= "Mi" id= "mathjax-span-1075" style= "Font-family:mathjax_math; Font-style:italic; " >e t unset p u MongoDB increase and deletion check (a)

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.