大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说MongoDB语句入门(4)[亲测有效],希望您对编程的造诣更进一步.
![MongoDB语句入门(4)[亲测有效]插图1 MongoDB语句入门(4)](/wp-content/themes/justnews/themer/assets/images/lazy.png)
创建数据库
语法:
use database_name;
代码100分
注意:如果该数据库不存在,则创建,如果该数据库存在,则是切换,如果创建了数据库,没有任何操作,则会自动删除该数据库。
![MongoDB语句入门(4)[亲测有效]插图3 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
可以使用db命令查看当前所处的数据库
![MongoDB语句入门(4)[亲测有效]插图5 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
查看数据库
语法:
代码100分show dbs;
![MongoDB语句入门(4)[亲测有效]插图7 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
创建集合
语法:
db.集合名.insert({})
该语法意思是向集合里面添加文档,db表示最近一次use的数据库,最近一次use的是谁,那么这个db就代表谁。
注意:MongoDB里面的集合是隐式创建的,就是说无需创建,直接使用。
![MongoDB语句入门(4)[亲测有效]插图9 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
查看集合
语法:
代码100分show tables;
show collections;
![MongoDB语句入门(4)[亲测有效]插图11 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
查询集合里的文档
语法:
db.集合名.find() # 查询所有
db.集合名.findOne() # 查询第一个文档
![MongoDB语句入门(4)[亲测有效]插图13 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
删除集合
语法:
db.集合.drop()
![MongoDB语句入门(4)[亲测有效]插图15 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
删除数据库
语法:
db.dropDatabase();
![MongoDB语句入门(4)[亲测有效]插图17 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
帮助命令
语法:
help
![MongoDB语句入门(4)[亲测有效]插图19 MongoDB语句入门(4)[亲测有效]](/wp-content/themes/justnews/themer/assets/images/lazy.png)
数据库相关的帮助命令
语法:
db.help()
集合相关的帮助命令
语法:
db.集合名.help()
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/7094.html