【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
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 could 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 expect for tags;
Example 2: return dall fields expect 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 could add the $atomic field to avoid this case. For example:
4. Update
4.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.
” 从中感到了作者的欢喜和忧愁,有翻译不妥或理解不到位的,还请指正:)1,David为什么要迁移?原文如下:写道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 to 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.看上去大概的意思是说:我们遇到了管理上的麻烦,虽然我们解决了备份问题。我们试图通过MySql集群解决,集群看上去很好但对于一个大量写应用来说却遇到了困难,同时我们也不确定集群是否适应我们的需求。于是David选择更换MySQL,选择了MongoDB。2、为什么选择MongonDB?写道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.Automated sharding being developed.Good documentation. 我想最重要的一点应该是:Very easy replication, including master-master support. In testing this caught up with our live DB very quickly and stayed in sync without difficulty. 非常容易的数据拷贝并且快速、一致。3、移植MongonDB后的问题。Schema-less:写道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......余下全文>>
” 从中感到了作者的欢喜和忧愁,有翻译不妥或理解不到位的,还请指正:)1,David为什么要迁移?原文如下:写道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 to 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.看上去大概的意思是说:我们遇到了管理上的麻烦,虽然我们解决了备份问题。我们试图通过MySql集群解决,集群看上去很好但对于一个大量写应用来说却遇到了困难,同时我们也不确定集群是否适应我们的需求。于是David选择更换MySQL,选择了MongoDB。2、为什么选择MongonDB?写道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.Automated sharding being developed.Good documentation. 我想最重要的一点应该是:Very easy replication, including master-master support. In testing this caught up with our live DB very quickly and stayed in sync without difficulty. 非常容易的数据拷贝并且快速、一致。3、移植MongonDB后的问题。Schema-less:写道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......余下全文>>