前言
提示:mongodb,我最喜欢的一点,就和python一样,是一门动态语言,变量类型随这个赋值类型而变化,更灵活的存储数据。
一、MongoDB是什么?
MongoDB是一个基于分布式文件存储 [1] 的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。它支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型。Mongo最大的特点是它支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引。
二、MongoDB
1.简单的知识图谱
2.mongoDB 增删改查操作
以下内容引用博客:https://www.jianshu.com/p/0c04ec964109
1、增
db.students.insert({“name”:“ziksang”}) 这是往集合中增加一条document 我们可以看出来如果一条一条插数据的话,会死的,而且命令输入太麻烦 所以我们可以用
mongoimport --db test --collection restaurants --drop --file ~/downloads/primer-dataset.json
mongoimport代表导入数据
–db test 代表选择那个数据库
–collection restaurants 代表选择那个集合
–drop 删除里面所有的所有document
–file 代表导入文件 ~/downloads/primer-dataset.json 表示文件路径,你可以直接用鼠标托到cmd里面就可能以 文件格式要这样:
{"name":"aaaaaa","age":20,"sex":"boy","hobby":["f","b","c"],"scroe":{"shuxue":20,"english":100}} {"name":"bbbbbb","age":10,"sex":"boy","hobby":["a","b","c"],"scroe":{"shuxue":80,"english":100}} {"name":"cccccc","age":3,"sex":"boy","hobby":["a","b","c"],"scroe":{"shuxue":20,"english":70}} {"name":"dddddd","age":20,"sex":"boy","hobby":["d","b","c"],"scroe":{"shuxue":10,"english":70}} {"name":"ffffff","age":10,"sex":"boy","hobby":["a","b","c"],"scroe":{"shuxue":20,"english":100}} {"name":"gggggg","age":20,"sex":"boy","hobby":["a","b","c"],"scroe":{"shuxue":20,"english":100}} {"name":"hhhhhh","age":8,"sex":"boy","hobby":["h","b","c"],"scroe":{"shuxue":20,"english":80}} {"name":"jjjjjj","age":20,"sex":"boy","hobby":["a","b","c"],"scroe":{"shuxue":40,"english":60}} {"name":"kkkkkk","age":8,"sex":"boy","hobby":["a","b","c"],"scroe":{"shuxue":20,"english":80}} {"name":"llllll","age":20,"sex":"boy","hobby":["a","b","c"],"scroe":{"shuxue":20,"english":100}} {"name":"qqqqqq","age":20,"sex":"boy","hobby":["a","b","c"],"scroe":{"shuxue":20,"english":100}}
2、删
db.dropDatabase() 删除你所在的当前数据库!!这个一定要小心,不会给你任何提示,然后就删除了
db.students.drop() 删除数据库中students集合
db.students.remove({“age”:20}) 删除所有students集合中age:20的文档
db.students.remove({“age”:100},{ justOne: true }) 删除最前面一条age:100的文档
3、改
db.students.update({“name”:“qqqqqq”},{$set:{“age”:100}}) 单个修改 ,把学生集合中 name =qqqqq 的 age改成100,但只能修改最上面的一条
db.students.update({},{$set:{“age”:100}},{multi:true})多个修改 , 查询条件为所有,把所有人的年纪都改成100 mult:true 这个表示多条件更改
db.students.update({“name”:“qqqqqq”},{“name”:“iiiiii”,“age”:100}) 把集合中的一个document完整替换。把name叫qqqqqq的一整条document 全部替换成{“name”:“iiiiii”,“age”:100}
4、查
db.restaurants.find() 如果find里没有查询条件时,则是列出集合中所有的文档
db.students.find({“scroe.shuxue”:20}) 这个是精确匹配
db.students.find({“scroe.shuxue”:20,“scroe.english”:100}) 多选项匹配,因为集合中的文档可以存js中的各种数据类型,里面传的是一个对象.属性来进行查询
条件查询
db.students.find({“scroe.shuxue”:{$gt:50}}) 选择数学成绩大于50的
db.students.find({“scroe.shuxue”:{$gte:80}}) 选择数学成绩大于等于80的
db.students.find({“scroe.shuxue”:{$lt:80}}) 选择数学成绩小于80的
db.students.find({“scroe.shuxue”:{$lte:80}}) 选择数学成绩小于等于80的
db.students.find({$or : [{“age”:3},{“age”:10}]}) 选择年龄等于3岁或者10岁的都可以
db.students.find().sort({“scroe.shuxue”:-1,“age”:1}) 排列,进入学生集合查询,进行 分数降序排,如果分数相同,则年龄升序排 -1表示降序 1表示升序
作者:Ziksang 链接:https://www.jianshu.com/p/0c04ec964109 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
3.mongoDB 中文网页
MongoDB中文手册|官方文档中文版:https://docs.mongoing.com/mongodb-crud-operations
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。