MongoDb基本操作
2016-06-23 15:26
621 查看
基本操作
简单操作
mongo #连接mongodb >show dbs #查看所有数据库 local 0.078125GB test 0.203125GB >use local #切换到local switched to db local > show collections #查看local的所有collection startup_log >db.startup_log.find() #产看startup_log { "_id" : "jlan-pc-1466044795232", "hostname" : "jlan-pc", "startTime",...} > db.createCollection('startup_log2') #创建collection { "ok" : 1 } >db.startup_log.remove() #清空collection
数据导出
mongoexport -d local -c startup_log -o startup_log.json #把startup_log导出为json文件,在终端执行 mongoexport -d local -c startup_log --csv -f _id,hostname,startTime -o startup_log.csv #startup_log导出为csv文件,--csv表示导出为csv格式,-f表示字段名;
数据导入
mongoimport -d local -c startup_log2 --file startup_log.json #把json文件导入collection,--file用于指定文件 mongoimport -d local -c startup_log2 --type csv --headerline --file startup_log.csv #把csv文件导入collection,--headerline表示忽略第一行
高级操作
修改collection的字段类型mongo可以通过find(...).forEach(function(x) {})语法来修改collection的field类型。
假设collection为hotels_info,field为dpcount:
db.hotels_info.find({dpcount:{$exists:true}}).forEach(function(x){ x.dpcount=new NumberInt(x.dpcount); db.hotels_info.save(x); })
查询操作
db.hotels_info.find({'dpcount':{'$gte':200}},{'id':1,'name':1,'_id':0}) #第一个{}中设定查询条件,第二个{}中设定需要显示的字段
相关文章推荐
- 分享微信开发Html5轻游戏中的几个坑
- Android之获取手机上的图片和视频缩略图thumbnails
- 如何在 Fedora 上安装 MongoDB 服务器
- PHP添加yaf xhprof mongodb 同理
- mongodb安装
- 数据库链接字符串查询网站
- 如何在 Ubuntu 上安装 MongoDB
- DB2实例管理
- DB2实例管理
- 保障MySQL数据安全的14个最佳方法
- mysql问答汇集
- 信息安全聚合 Sec-News 的重构之路
- 第三章 数据库备份和还原
- 创建一个空的IBM DB2 ECO数据库的方法
- Access 2000 数据库 80 万记录通用快速分页类
- 开通一个数据库失败的原因的和解决办法
- 一个简单的asp数据库操作类
- CentOS下DB2数据库安装过程详解
- EasyASP v1.5发布(包含数据库操作类,原clsDbCtrl.asp)第1/2页