mongodb的操作备忘录

cd D:\programs\MongoDB\Server\3.4\bin

--启动mongodb服务
mongod --dbpath "D:\programs\MongoDB\Server\3.4\data\db"
--启动mongodb客户端
mongo

--连接远程数据库
mongo --host 10.128.137.21 --port 27017

--导出数据
mongoexport /host 10.128.137.21 /port 27017 /d maxus_tsp /c tspAppStat /o d:\tspAppStat_data.json

--导入数据
mongoimport /host 127.0.0.1 /port 27017 /d maxus_tsp /c carCan /file d:\carCan_p.json
--按条件导出
mongoexport /host 127.0.0.1 /port 27017 /d maxus_tsp /c carCan /q "{cd: {$regex:'^2018-03-26'}}" /o d:\carCanTmp1.json

--启动本地数据库
mongod --dbpath "D:\programs\MongoDB\Server\3.4\data\db"

--删除集合
>use maxus_tsp
>db.tspAppStatDone.drop()

--删除集合数据
>use maxus_tsp
>db.tspAppStat.remove({})
>db.tspAppStat.remove({"name":"zhangshan"})
>db.tspAppStat.remove({"d": {$regex: "^2017-12-22"}})
>db.tspAppStat.remove({"d": {$gte:"2017-12-05 00:00:00"}})
>db.carCan.remove({"cd": {$lte:"2017-12-29 00:00:00"}})


--模糊匹配查询
> db.tspAppStat.find({"d": {$regex: "^2017-12-06"}})
> db.getCollection('carGPS').find({"vin":"LSKG5GC17HA098022", "cd":{$gte: "2018-01-25 00:00:00", $lte: "2018-01-30 00:00:00"}}).count()

--聚合
db.getCollection('carGPS').aggregate([{$group: {_id: "$vin", num_tutorial: {$sum: 1}}}])
--and / or 查询
db.getCollection('carCanHis').find({vin:"LSKG4GC17JA051727", $or:[{pm:"0"},{pm: "2"}]}).count()

--创建索引
db.COLLECTION_NAME.ensureIndex({"cd":1},{background:true})
--查看索引
db.COLLECTION_NAME.getIndexes()

--修改字段类型
db.carCanHis.find({ma: {$exists:true}}).forEach(function(x) {x.ma = new NumberInt(x.ma); db.carCanHis.save(x);})

你可能感兴趣的:(hadoop大数据,mongodb)