MongoDB $ numeric key
equal
: In what field MongoDB value equal to what is actually a ":" to get such "name": "lin"
$ eq and top query result is the same
Greater than in MongoDB is> Number We: $ gt example
Greater than or equal in MongoDB is greater than or equal to> = number we use: $ gte
Less than in MongoDB less than <No. We: $ lt
Or less in MongoDB is less than or equal to <= number we use: $ lte
MongoDB $ keyword query
$or
Query what time or what conditions
db.collection.find ({$ or: [{ "username": "silly Bata"}, { "username": "Tangchaolizai"}]}) query username is "silly Bata" and "Tangchaolizai " The data.
$in
Query "year" meet the data in [2018,2019,2020] in
db.collection.find ({ "year": {$ in: [2018,2019,2020]}}) # satisfies a condition can be
$all
Query data in the data meet all year list
db.collection.find ({year: {$ all: [2018,2019,2020,2021]}}) # query subset
MongoDB $ modifier
MongoDB's update modifier: $ inc $ set $ unset $ push $ pull
$inc
db.collection.update ({ "username": "silly Bata"}, {$ inc: { "age": 10}}) # username to let 傻了吧嗒
people under 10 years of age increased
db.collection.update ({ "username": "silly Bata"}, {$ inc: { "age": - 10}}) # username to let 傻了吧嗒
people under 10 years of age to reduce
$set
For updating the data, it does not automatically add a
db.collection.update ({ "username": "silly Bata"}, {$ set: { "age": 100}}) # username to let 傻了吧嗒
people update of age is 100 years old
$unset
To delete Key (field), equivalent to a relational database to delete the field
db.collection.update ({ "username": "silly Bata"}, {$ unset: { "age": 100}}) # delete the username 傻了吧嗒
of the person's age field
$push
Used to Array (list) a data type to increase new method element corresponds in Python list.append ()
First db.collection.updateMany ({}, {$ set: { "test_list": [1,2,3,4]}}) # are added for all data a list test_lsit
Next we add a team list: to the "username" 傻了吧嗒
of the Document "test_list" add a 5
db.collection.update ({ "username": "silly Bata"}, {$ Push: { "test_list":}}. 5) # \ (Push a new element is added to the trailing end Array (list) of { \) Push: { "test_list":}}. 5
$pull
$ Pull is designated to delete Array (list) data types to a certain element
db.collection.update ({ "username": "silly Bata"}, {$ pull: { "test_list": 4}}) # the "username" is 傻了吧嗒
the Document in "test_list" delete a 4
NOTE: If Array (list) if there are a plurality of data types will delete all 4!
So, as long as the conditions are satisfied, it will meet all the conditions of the Array data all cleared
$pop
Delete "username" is equal to 傻了吧嗒
the last element of test_list
db.collection.update ({ "username": "silly Bata"}, {$ pop: { "test_list": - 1}}) # deleted as "username" 傻了吧嗒
"test_list" in the Document of the first element
db.collection.update ({ "username": "silly Bata"}, {$ pop: { "test_list": 1}}) # Delete "username" is 傻了吧嗒
the Document in "test_list" the last element
{$ Pop: { "test_list": -1}} -1 representative of the front, side represents the last 1 (Python and vice versa)