One: Insert operation
The previous article also said that the document is stored in the "k-v" format, if you are familiar with JSON, I believe that learning MongoDB is extremely easy, we know that the JSON value
It could be "string", maybe "array", and possibly an inline JSON object, and the same way is appropriate for Bson.
Common insert operations also exist in two forms: "Single insert" and "BULK insert".
① Single Insert
As I said earlier, the MONGO command opens a JavaScript shell. So JS syntax in this can work, it seems to be not very bull X.
② BULK Insert
The difference between this thing and the "single insert" I believe you should know that because there is no "bulk Insert method" provided to the shell in MongoDB, it doesn't matter, driver in each language
With MongoDB internal bulk insertion method, because this method is indispensable, if you want to simulate the next batch insert, you can write a for loop, inside is insert.
Two: Find operation
In the daily development, we play the query, play the most is two categories:
①:, >=, <, <=,! =, =.
②:and,or,in,notin
These operations are encapsulated in MongoDB, as described below:
<1> "$gt", "$gte", "$lt", "$lte", "$ne", "No special keywords", which correspond to one by one above, give a few examples.
<2> "No keywords", "$or", "$in", "$nin" I also give a few examples
<3> there is a special match in MongoDB that is "regular expression", which is very powerful.
<4> sometimes query is very complex, very egg pain, but it doesn't matter, MongoDB gave us a big move, it is $where, why say, because $where in the value
Is that we are very familiar with the very love of JS to help us Yimapingchuan.
Three: Update operation
Update operation is nothing more than two, the overall update and local update, the use of the occasion I believe we are also clear.
<1> Overall Update
I do not know you can remember, I in the last article when using the update, in fact, that update is the overall update.
<2> Local Updates
Sometimes we just need to update a field instead of the whole update, so what do we do? Easy question, MongoDB has provided us with two of
Modifiers: $inc and $set.
① $inc modifier
$inc is the abbreviation of increase, the students who have learned SQL Server should be familiar with, for example, we do an online user status record, each modification will be on the original basis
Self-increment $inc The specified value, if the "document" does not have this key, then the key will be created, the following example can be understood.
② $set modifier
Don't say anything, just the code.
<3> Upsert operation
This is the "word" created by MongoDB, you remember the first parameter of the Update method is "query condition"? , then this upsert operation is saying: if I
Did not find, I was in the database add a, in fact, this also has the benefit, is to avoid me in the database inside the judge is update or add operation, use is very simple
Set the third parameter of update to TRUE.
<4> Batch Update
In MongoDB if you match more than one, the default is to update only the first one, then if we have a need to batch update, then the implementation in MongoDB is also very simple
, set to True in the fourth parameter of the update. The example is not to be lifted.
Four: Remove operation
Remove if no parameters will delete all data, oh, very dangerous operation, in MongoDB is a non-revocable operation, think twice before the line.
Transfer from http://www.cnblogs.com/qq75077027/archive/2012/12/26/2834766.html
MongoDB detail additions and deletions to search and change