mongoDB基本操作

本文详细介绍了MongoDB的基本操作,包括使用help获取帮助,showdbs显示数据库列表,use切换数据库,insert插入数据,find查询数据,update更新数据,remove删除数据,drop删除集合,getIndexes查询索引和ensureIndex创建索引等核心命令。通过这些操作,读者可以快速掌握MongoDB的日常管理和数据处理技巧。

基本操作
首先要学会的是help
show dbs
use imooc
db.imooc_collection.insert({}) //创建一个空的数据库
db.imooc_collection.insert({x:1}) //插入数据自动创建数据库
db.imooc_collection.find() //查找数据,默认查找所有
db.imooc_collection.find({x:1})
db.imooc_collection.update({x:1},{x:2}) //更新数据,默认更新第一条数据
db.imooc_collection.update({x:4},{x:8},true) //不存在更新数据则插入数据
db.imooc_collection.update({x:1},{x:3},false,true) //更新所有x=1的数据
db.imooc_collection.remove({x:2}) //必须带参数
db.imooc_collection.drop() //删除表
db.imooc_collection.getIndexes() //查询索引
db.imooc_collection.ensureIndex({n:1}) //创建索引

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值