[MongoDB] The basic operation of Mongodb, Insert \ Query \ Delete \ Update, mongodboperation

Source: Internet
Author: User

[MongoDB] The basic operation of Mongodb, Insert \ Query \ Delete \ Update, mongodboperation
1, Insert

MongoDB is database storing document object, the type of which is called Bson. (like JSON );

Example: // document defination

 

 

Now after using command [db. posts. insert (doc)], you will insert record successfully if seeing

The following picture.

 

2. Query

One of the fundamental functions of MongoDB is to support query dynamically, which is the same as the troditional relational database, but more effiecieny than that.

2.1 Query Expression Ojbects:

Query expression objects document is also a bson-structure document. For example, we cocould use the following the command to find all the record in the collections:

 

2.2 Query Item

In addition to Query expression object, Mongodb still support extra argument items. For example, you may only wanna return some certain fields. For example:

Example 1: return all the fields CT for tags;

 

Example 2: return dall fields exact CT for comments and tags = "albert"

 

Example 3: return the only field 'name' and gender = 'male'


3. Remove

Removing operation is used to remove records from the collections. Example:

 


Advice: It's better to use _ id as condition when executing the remove operation/

Attention: In some conditions, when you are ready to remove one record, maybe in the meantime the update operation is updating this record which makes the reomve operation failed. as for this case, you can add the $ atomic field to avoid this case. for example:


4. Update4.1 Grammar


Argument Description:

Criteria: the object used to set query conditions

Objnew: Object used to set update content.

Upsert: if record exists, it will update it. Else insert a new record.

Multi: if multi matches conditoin, it will update all the records.

Attention: By fault, mongoDB will update the first record that matches the query condition.

 

 

 

 


Why did David Mytton migrate data from MySQL to MongoDB?

"I felt the joy and sorrow of the author. If some translation is inappropriate or cannot be understood, please correct me. :) 1. Why does David migrate? The original article is as follows: Write The problem we encountered was administrative. we wanted to scale using replication but found that MySQL had a hard time keeping up, especially with the initial sync. as such, backups became an issue, but we solved that. however, scaling MySQL onto multiple clustered servers as we plan to do in the future is difficult. you either do this through replication but that is only really suited Read-heavy applications; or using MySQL cluster. the cluster looks very good but I have read about some problems with it and was unsure of it's suitability for our needs. it seems that we have encountered management problems, although we have solved the backup problem. We try to solve the problem through the MySql cluster. The cluster looks good, but it is difficult for a large number of write applications. At the same time, we are not sure whether the cluster meets our needs. So David chose to replace MySQL and MongoDB. 2. Why MongonDB? Wrote Very easy to install. PHP module available. very easy replication, including master-master support. in testing this caught up with our live DB very quickly and stayed in sync without difficulty. automatically sharding being developed. good documentation. I think the most important thing is: Very easy replication, including master-master support. in testing this caught up with our live DB very quickly and stayed in sync without d Ifficulty. It is very easy to copy and fast and consistent data. 3. Problems after MongoDB is transplanted. Schema-less: Write Schema-lessThis means things are much more flexible for future structure changes but it also means that every row records the field names. we had relatively long, descriptive names in MySQL such as timeAdded or valueCached. for a small number of rows, this extra storage onl ...... remaining full text>

Why did David Mytton migrate data from MySQL to MongoDB?

"I felt the joy and sorrow of the author. If some translation is inappropriate or cannot be understood, please correct me. :) 1. Why does David migrate? The original article is as follows: Write The problem we encountered was administrative. we wanted to scale using replication but found that MySQL had a hard time keeping up, especially with the initial sync. as such, backups became an issue, but we solved that. however, scaling MySQL onto multiple clustered servers as we plan to do in the future is difficult. you either do this through replication but that is only really suited Read-heavy applications; or using MySQL cluster. the cluster looks very good but I have read about some problems with it and was unsure of it's suitability for our needs. it seems that we have encountered management problems, although we have solved the backup problem. We try to solve the problem through the MySql cluster. The cluster looks good, but it is difficult for a large number of write applications. At the same time, we are not sure whether the cluster meets our needs. So David chose to replace MySQL and MongoDB. 2. Why MongonDB? Wrote Very easy to install. PHP module available. very easy replication, including master-master support. in testing this caught up with our live DB very quickly and stayed in sync without difficulty. automatically sharding being developed. good documentation. I think the most important thing is: Very easy replication, including master-master support. in testing this caught up with our live DB very quickly and stayed in sync without d Ifficulty. It is very easy to copy and fast and consistent data. 3. Problems after MongoDB is transplanted. Schema-less: Write Schema-lessThis means things are much more flexible for future structure changes but it also means that every row records the field names. we had relatively long, descriptive names in MySQL such as timeAdded or valueCached. for a small number of rows, this extra storage onl ...... remaining full text>

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.