典型NoSQL数据库的安装和使用——MongoDB安装和使用

安装方式

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名、网页空间、营销软件、网站建设、东城网站维护、网站推广。

采用apt-get install MongoDB命令直接进行,采用源码包安装也可以

hadoop@dblab:/$ sudo apt-get update

hadoop@dblab:/$ sudo apt-get install -y mongodb-org

hadoop@dblab:/$ mongo -version

MongoDB shell version: 3.2.22

hadoop@dblab:/$ sudo service mongodb start #启动MongoDB

hadoop@dblab:/$ mongo  #进入MongoDB Shell模式典型NoSQL数据库的安装和使用——MongoDB安装和使用

> use school   #切换到shcool数据库,使用时会自动创建

switched to db school

> db.createCollection('teacher')    #创建集合

{ "ok" : 1 }

> show dbs   #显示数据库列表

local  0.000GB

school  0.000GB

> db.student.insert({_id:1,sname:'zhangsan',sage:20})   #插入数据

WriteResult({ "nInserted" : 1 })

> db.student.insert({_id:2,sname:'lisi',sage:22})   #插入数据

WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 2 })

> use school

switched to db school

> show collections   #显示当前数据库的集合

student

teacher

#查找数据

> db.student.find()   #查找所有记录

{ "_id" : 1, "sname" : "lisi", "sage" : 22 }

{ "_id" : 2, "sname" : "lisi", "sage" : 22 }

> db.student.remove({_id: 2})    #删除数据

WriteResult({ "nRemoved" : 1 })

> db.student.find()

{ "_id" : 1, "sname" : "lisi", "sage" : 22 }

> db.student.insert({_id:2,sname:'zhangsan',sage:25})

WriteResult({ "nInserted" : 1 })

> db.student.find()

{ "_id" : 1, "sname" : "lisi", "sage" : 22 }

{ "_id" : 2, "sname" : "zhangsan", "sage" : 25 }

#修改数据

> db.student.update({_id:2},{$set:{sage:88}},false,true)

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.student.find().pretty()

{ "_id" : 1, "sname" : "lisi", "sage" : 22 }

{ "_id" : 2, "sname" : "zhangsan", "sage" : 88 }

#删除数据

> db.student.remove({sname:'lisi'})

WriteResult({ "nRemoved" : 1 })

#删除集合

> db.student.drop()

> show collections

teacher

> exit  #退出MongoDB Shell模式

bye

网页题目:典型NoSQL数据库的安装和使用——MongoDB安装和使用
本文URL:https://www.cdcxhl.com/article2/pichic.html

成都网站建设公司_创新互联,为您提供网站设计电子商务用户体验小程序开发网站制作移动网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

小程序开发