本文主要是介绍mongDB--零碎知识搜集,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
启动mongo
[root@localhost bin]# ./mongod --fork --dbpath=/data/mongoCluster/master/data --port=27017 --logpath=/data/mongoCluster/master/mongodb-linux-i686-3.2.6/log --journal
日期查询
db.liveEpgUserVisits.find({"inputTime":{$gte:ISODate("2014-09-15T00:00:00Z"),$lte:ISODate("2014-09-16T00:00:00Z")}}).count();
mapreduce 进行SUM操作
res = db.runCommand({mapreduce:'liveEpgUserVisits',map:function() {emit({provice:this.provice}, {"data":[{"mac":this.mac}],"visit":this.visit});},reduce:function(key, value) {var ret = {data:[]}, visit=0;var macs = {};var sum = 0;for(var i in value) {var ia = value[i];for(var j in ia.data) {if(!macs[ia.data[j].mac]) {macs[ia.data[j].mac] = true;ret.data.push(ia.data[j]);}}sum += Number(ia.visit);}ret.visit = sum;return ret;},query:{"mac":"9ad8f378121cbe8d56f6cfe5b7edcbd1"},finalize:function(key, values){return [{count:values.data.length},{visit:values.visit}];},out:'tmp_mo_spcode_consignid_1',verbose:true
})
去重统计
db.runCommand({"distinct":"liveEpgUserVisits201501","key":"mac"}).values.length();
详见:http://y-zjx.iteye.com/blog/1313826
这篇关于mongDB--零碎知识搜集的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!