安装mongodb数据库:
yum -y install mongodb-server mongodb
service mongod start #启动mongodb 服务
pstree -p | grep mongod #进程列表
chkconfig mongod on #开机启动mongod服务
进入mongodb数据库:
mongo # 进入mongodb命令行模式
show dbs #显示所有的表
db #当前数据库
show tables #当前数据库多少个集合
show collections #当前数据库多少个集合[*]
#创建命令:
db.c1.insert({name:”tom”}); #往表添加一条数据
show dbs #显示当前test数据库
show tables #当前数据库多少个集合
db.c1.find(); #查看数据列表
#删除命令:
#方法一:删除整张表
db.c1.remove(); #删除表所有数据
db.c1.find(); #查看数据列表
#方法二:删除一条数据
db.c1.remove({sex:”man”});
> db.c1.find()
#修改命令:
#方法一
db.c1.insert({name:”tom”}); #往表添加一条数据
db.c1.update({name:”tom”},{name:”tom_up”}); #更新数据
#方法二
db.c1.insert({name:”tom”,age:25})
db.c1.find()
db.c1.update({name:”tom”},{$set:{name:”tom-up”}})
db.c1.find()
#方法三
db.c1.update({name:”tom-up”},{$set:{sex:”man”}});
db.c1.find()
发表回复