a) Increase
1. Add a record
Db.test.insert ({name: ' AA ', age:20});
2. Add multiple Records
There seems to be no way to find a MySQL-like insert into tb_name values (), but
JS syntax can be used in MONGO, so you can use the For loop to add multiple records
for (i=0;i<10;i++) Db.test.insert ({' name ': ' BB ', ' Age ': 21+i});
II) by deleting
1. Delete a record (the method of deleting the specified record is not found)
Db.test.remove ({' name ': ' AA '}, 1)
2. Delete more than one record
Db.test.remove ({' name ': ' AA '})
III) Change
1. Modify a record
Db.test.update ({' name ': ' User3 ', {$set: {' age ': 24}}})
2. Modify multiple records (third parameter, multi:1)
Db.test.update ({' name ': ' User2 '},{$set: {' age ': 25}},{' multi ': 1})
IV) Check
1, query a record
Db.test.findOne ({' name ': ' User1 '})
2. Querying multiple records
Db.test.find ({' Age ': +}). Limit (10)
3. Query sort (sort function, 1 for ascending,-1 for descending)
Db.test.find ({' ClassID ': 1}). Sort ({' Age ': 1})
4. Fuzzy query (using regular expressions)
Db.test.find ({' name ': {$regex:/Chen./}})
Conditional syntax:
Greater than
{' age ': {$gt: 18}}
Greater than or equal
{' age ': {$gte: 18}}
Equals
{' age ': {$eq: 18}}
Less than or equal
{' age ': {$lte: 18}}
Less than
{' age ': {$lt: 18}}
Not equal to
{' age ': {$ne: 18}}
A and B
{' name ': ' User5 ', ' Age ': 25}
A or B
{$or: [{' Name ': ' user4 '},{' name ': ' User5 '}]}
A and (b or C)
{' name ': ' User5 ', $or: [{' Age ': 25},{' age ': 26}]}
(A and B) or (C and D)
{$or: [{' Name ': ' User4 ', ' age ': ' + '},{' name ': ' User5 ', ' Age ': 25}]}
MongoDB additions and deletions to search