MongoDB Introduction to the MongoDB database of the deletion of the check and change operation _mongodb

Source: Internet
Author: User
Tags bulk insert modifier mongodb

Read on an article, I believe we will know how to open MongoDB, this article on the next one of the additions and deletions, first when we use the same way to open MongoDB, suddenly

Dumbfounded, rub, unexpectedly opened, carefully observe the "underlined area" information, found that the DB folder has a similar "lock file" to prevent the opening of the MongoDB, the next thing we have to do is

is to kill it, after the opening success, about MongoDB management will be shared in subsequent articles.

One: Insert operation

The previous article also said that the document is stored in the "k-v" format, if you are more familiar with JSON, I believe that learning MongoDB is extremely easy, we know the value of JSON

It may be "string", possibly "array", or it may be a JSON object embedded in it, the same way for Bson.

Common inserts also exist in two forms: "Single insert" and "BULK insert."

① Single Insert

As previously stated, the MONGO command opens a JavaScript shell. So the syntax of JS in here all work, it seems to be not very cow X.

② BULK Insert

The difference between this thing and "a single insert." I believe you should know, because the MongoDB is not provided to the shell of the "bulk insertion method", it does not matter, the driver of each language has been through the MongoDB with the internal bulk insertion method, because the method is indispensable, If you want to simulate the bulk INSERT, you can write for the loop, the inside is insert.

Two: Find operation

In the daily development, we play the query, play the most is also two categories:

①: >=, <=,!=, =.

②:and,or,in,notin

These operations are packaged inside the MongoDB and are described below:

<1> "$gt", "$gte", "$lt", "$lte", "$ne", "No special keywords", which correspond to the above one by one, give a few examples.

<2> "No keywords", "$or", "$in", "$nin" I also cite a few examples

<3> there is a special match in the MongoDB, which is "regular expression", which is very powerful.

<4> Sometimes the query is very complex, very egg pain, but it doesn't matter, MongoDB give us a big recruit, it is $where, why so said, because the value of $where

Is that we are very familiar with the very love of JS to help us Yimapingchuan.

Third: Update operation

Update operation is nothing more than two, the overall update and local update, the use of the occasion I believe that we are also aware of.

<1> Overall Update

I do not know you can remember, when I used the update in the last one, in fact, that update is the overall update.

<2> Local Update

Sometimes we just need to update a field, not a whole update, so what do we do? Easy question, MongoDB has provided us with two

Modifier: $inc and $set.

① $inc modifier

$inc is the abbreviation of increase, students who have studied SQL Server should be familiar with, for example, we do an online user status record, each modification will be based on the original

Self-$inc The specified value, if this key is not in the document, the key is created, as the following example will read.

② $set modifier

Don't say anything, just go to the code.

<3> Upsert operation

This is the "word" created by MongoDB, do you remember the first parameter of the Update method is "query criteria"? , then this upsert operation is to say: if I

Did not find, I will be added in the database, in fact, this also has the advantage, is to avoid me in the database to determine whether the update or add operation, it is very simple to use

Set the third parameter of update to TRUE.

<4> Batch Update

If multiple matches are matched in MongoDB, only the first one is updated by default, then it is also easy to implement in MongoDB if we have a requirement to be updated in batches.

, set to True in the fourth parameter of update. The example will not be lifted.

Four: Remove operation

This operation in the last article simply said, here is not to repeat.

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.