Mongo command:
- Show Databases/dbs;
- Use test;
- Show Tables/collections;
- Db.help ()
- Db.createcollection (' user ')
- Db.user.insert ({name: ' Sky ', age:22})
- Db.user.insert ({_id:2, Name: ' Allen ', age:23})
- Db.user.find ()
- Db.user.drop ();
- Db.dropdatabase ();
- Db.stu.remove ({sn: ' 001 '})
- Db.stu.remove ({sn: ' 001 '}, True) #第二个属性表示只影响一行
- Db.stu.update ({name: ' Liubei '},{name: ' Guanyu ', age:20}) # The update in MONGO is a new document that replaces the old document directly, not the modification. If you change only one field, you need to use the set
- Db.stu.update ({name: ' Guanyu '},{$set: {name: ' Sky '}})
Update Specific actions:
- $set Modify the value of a column
- $unset Delete a column
- $rename Rename a column
- $inc Grow a column
Db.stu.update ({name: ' Wukong '},{$set: {name: ' DZSF '}, $unset: {jingu:1}, $rename: {sex: ' Gendar '}, $inc: {age:1}}) #默认u Pdate only 1 lines.
Db.stu.update ({name: ' Wukong '},{$set: {name: ' DZSF '}, $unset: {jingu:1}, $rename: {sex: ' Gendar '}, $inc: {age:1}},{m Ulti:true})
#如果有这条记录就更新, if not, insert
Db.stu.update ({name: ' Bill '},{$set: {name: ' Bill ', Sex: ' M ', age:500}},{upsert:true})
#但是如果我要插入的字段不止这些, when inserting, you need to add more fields, using Setoninsert.
Db.stu.update ({name: ' Kevin '},{$set: {name: ' Bill ', Sex: ' M ', age:500}, $setOnInsert: {address: ' Shanghai '}},{upsert: True})
#第一部分查询表达式, the second part queries the column.
Db.stu.find ({},{name:1})
#id属性默认查出, if you don't want
Db.stu.find ({},{name:1, _id:0})
The basic crud for MongoDB learning notes