mongo的一些用法

来源:互联网 发布:linux下串口调试工具 编辑:程序博客网 时间:2024/05/08 10:40
1.同一个mongo不同数据库的表的拷贝
db.yc_order.find().forEach(function(d){ db.getSiblingDB('insurance-alltrust')['yc_order'].insert(d); });


2.不同mongo的库拷贝同一个mongo也可以直接拷贝库

db.copyDatabase("insurance-alltrust","insurance-anxin","localhost");   


3.字段是否存在的java用法

MongoBaseDao.findList("travel_poi", new Document("nation",new Document("$exists",false)));


4.数组查询:

条件可以直接为 ‘citys’:'北京市' 或者是 ‘citys’:['北京市','上海市']


5.数据导出csv格式:

mongoexport --type=csv -d insurance -c travle_poi -q "{'realtime' : '20161109'}" -o acc.dat -f areaId,cityId,proviceId,timeType,realtime,forcasttime,data.rain,data.t_max


6.数据导入csv:

mongoimport -d insurance-alltrust -c hlg_city_b --type csv -f "month,value,value2,city,timeType" hlg_city_b


7.整体更新:

.update({name:'武汉'},{$set:{name:'武汉欢乐谷'}},{multi:true});


8.条件查询:(大小与):

new Document("washcar.begin", new Document("$lte", begin).append("$lt", today)) 大小与


9.空间索引:

1).球面索引

db.station.ensureIndex({loc:"2dsphere"},{unique:true, dropDups:true})

db.station.find( { loc : { $near : { $geometry :   { type : "Point" , coordinates : [20 , 108] } , $maxDistance : 1000000  } } } )


2).平面索引

db.station.ensureIndex({loc:"2d"},{unique:true, dropDups:true})

db.station.find( { loc : { $near : [20 , 108] } } )



10 排序:

sort 方法 中 字段1代表正序  -1是逆序

new Document("washcar.begin", new Document("$lte", begin).append("$lt", today)) 大小与


0 0
原创粉丝点击