在MongoDB下完成如下操作:
1.进入my_test数据库(3分)
use my_test
2.向数据库的users集合中插入一个username为sunwukong的文档(3分)
db.users.insert({username:"sunwukong"})
3.向数据库的users集合中插入一个{username:"zhubajie"}和一个{username:'shaheshang",address:"liushahe"}的两个文档(3分)
db.users.insert([{username:"zhubajie"},{username:'shaheshang",address:"liushahe"}])
或者可以
db.users.insertMany([{username:"zhubajie"},{username:'shaheshang",address:"liushahe"}])
4.查询数据库users集合中的文档(3分)
db.users.find()
5. 统计数据库users集合中的文档数量(3分)
db.users.count()
6. 查询数据库users集合中username为sunwukong的文档(4分)
db.users.find({username:"sunwukong"})
7. 向数据库users集合中的username为sunwukong的文档,添加一个address属性,属性值为huaguoshan(4分)
db.users.update({username:"sunwukong"},{$set:{address:"huangongshan"}})
8. 使用{username:"tangseng"} 替换 username 为 zhubajie的文档(4分)
db.users.update({username:"zhubajie"},{username:"tangseng"})
9. 删除username为shaheshang的文档的address属性(4分)
db.users.update({username:"shaheshang"},{$unset:{address:""}})
10.删除address为huanguoshan的文档(4分)
db.users.remove({address:"huaguoshan"})
标签:username,users,MongoDB,db,sunwukong,小白,文档,实操,address
From: https://blog.csdn.net/2301_79659699/article/details/140465380