最近在使用php的mongo 扩展进行数据统计计算,其中有一个时间戳字段,由于精确到了毫秒,长度有13位,但由于开始的时候是以字符串的形式存储:
最近在使用php的mongo 扩展进行数据统计计算,其中有一个时间戳字段,由于精确到了毫秒,长度有13位,但由于开始的时候是以字符串的形式存储:
实例代码如下:
- { "_id" : ObjectId("504eea97e4b023cf38e34039"), "in_ts" : NumberLong("1347349143699"), "log" : { "guid" : "4D1F3079-7507-F4B0-E7AF-5432D5D8229D", "p" : "View_Prop_YepPage_Zheng", "cid" : "11", "url" : "http://shanghai.haozu.com/rental/broker/n/10481780", "rfpn" : "Listing_V2_IndexPage_All", "site" : "haozu", "agent" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)", "stamp" : "1347349162159", "cip" : "116.226.70.44", "referer" : "http://shanghai.haozu.com/shop/1464934/", "cstamp" : "1347349323125", "sessid" : "FA798056-F9E7-F961-41E0-CC95C850FA47", "uguid" : "C00FF55B-3D3D-4B31-4318-12345B0DBE64", "pn" : "View_Prop_YepPage_Zheng", "cstparam" : { "proId" : NumberLong(10481780), "brokerId" : "326792", "tradeType" : "2", "userType" : "0", "channel" : "site", "entry" : "1", "COMMID" : "1666" } }, "out_ts" : NumberLong("1347349466083"), "rule" : 0, "status" : "ok", "txid" : 0 }
后来改成数字格式:
实例代码如下:
- { "_id" : ObjectId("504eea97e4b023cf38e34039"), "in_ts" : NumberLong("1347349143699"), "log" : { "guid" : "4D1F3079-7507-F4B0-E7AF-5432D5D8229D", "p" : "View_Prop_YepPage_Zheng", "cid" : "11", "url" : "http://shanghai.haozu.com/rental/broker/n/10481780", "rfpn" : "Listing_V2_IndexPage_All", "site" : "haozu", "agent" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)", "stamp" : NumberLong("1347349162159"), "cip" : "116.226.70.44", "referer" : "http://shanghai.haozu.com/shop/1464934/", "cstamp" : "1347349323125", "sessid" : "FA798056-F9E7-F961-41E0-CC95C850FA47", "uguid" : "C00FF55B-3D3D-4B31-4318-12345B0DBE64", "pn" : "View_Prop_YepPage_Zheng", "cstparam" : { "proId" : NumberLong(10481780), "brokerId" : "326792", "tradeType" : "2", "userType" : "0", "channel" : "site", "entry" : "1", "COMMID" : "1666" } }, "out_ts" : NumberLong("1347349466083"), "rule" : 0, "status" : "ok", "txid" : 0 }为字符串时,使用下面的查询是正常的
- $query = array ('log.stamp' => array ('$gte' => ‘1347346800000’, '$lt' => ‘1347350400000’));
但是改为数字后,使用下面的查询,死活没有结果,但是直接在mongo客户端直接查询是有结果的:
实例代码如下:
- { "_id" : ObjectId("504eea97e4b023cf38e34039"), "in_ts" : NumberLong("1347349143699"), "log" : { "guid" : "4D1F3079-7507-F4B0-E7AF-5432D5D8229D", "p" : "View_Prop_YepPage_Zheng", "cid" : "11", "url" : "http://shanghai.haozu.com/rental/broker/n/10481780", "rfpn" : "Listing_V2_IndexPage_All", "site" : "haozu", "agent" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)", "stamp" : NumberLong("1347349162159"), "cip" : "116.226.70.44", "referer" : "http://shanghai.haozu.com/shop/1464934/", "cstamp" : "1347349323125", "sessid" : "FA798056-F9E7-F961-41E0-CC95C850FA47", "uguid" : "C00FF55B-3D3D-4B31-4318-12345B0DBE64", "pn" : "View_Prop_YepPage_Zheng", "cstparam" : { "proId" : NumberLong(10481780), "brokerId" : "326792", "tradeType" : "2", "userType" : "0", "channel" : "site", "entry" : "1", "COMMID" : "1666" } }, "out_ts" : NumberLong("1347349466083"), "rule" : 0, "status" : "ok", "txid" : 0 }为字符串时,使用下面的查询是正常的
- $query = array ('log.stamp' => array ('$gte' => ‘1347346800000’, '$lt' => ‘1347350400000’));
实例代码如下:
- db.haozu_success.find({'log.stamp':{$gte:1347346800000,$lt:1347350400000}})
php手册上也是这么个用法:
- $query = array ('log.stamp' => array ('$gte' => 1347346800000, '$lt' => 1347350400000));
花了好大一会找原因,开始时怀疑是php扩展的bug导致,经过一番思考.突然想到可能是类型问题导致,发现手册上有Types 介绍,所以正确的用法如下:
实例代码如下:
- $query = array ('log.stamp' => array ('$gte' => new MongoInt64($time_range['start']), '$lt' => new MongoInt64($time_range['end'])));
另外,在使用mapreduce进行数据统计时,为了防止cursor出现超时异常,还需要设置一下超时时间
实例代码如下:
- $map = new MongoCode ( '
- function(){
- var prop_id=this.log.cstparam.proId;
- var key=this.log.site+prop_id
- emit(key,{"channel":this.log.site,"prop_id":prop_id,"count":1});
- }
- ' );
- $reduce = new MongoCode ( '
- function(key,emits){
- var total=0;
- for(var i in emits){
- total+=emits[i].count;
- }
- return {"channel":emits[0].channel,"prop_id":eval(emits[0].prop_id),"count":total};
- }
- ' );
- $this->mongo_db->command ( array ('mapreduce' => $collection_name, 'map' => $map, 'reduce' => $reduce, 'out' => $tmp_result, 'query' => $query),array('timeout'=>self::MONGO_CURSOR_TIMEOUT) );
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » 使用php mongodb扩展时比较需要注意的事项
波比源码 » 使用php mongodb扩展时比较需要注意的事项
order levaquin without prescription levaquin 250mg drug
order avodart 0.5mg online buy generic celecoxib 200mg buy zofran 4mg pills
buy aldactone 100mg generic finasteride 1mg price purchase diflucan pills
oral ampicillin 500mg acillin without prescription erythromycin order online
purchase sildenafil for sale careprost ca purchase robaxin for sale
buy sildenafil generic cost suhagra 50mg order generic estradiol 1mg
order lamictal 50mg pill buy vermox 100mg buy retin generic
generic tadalis 20mg oral tadalis diclofenac 50mg price
order accutane 10mg accutane 40mg us cost zithromax 500mg
indocin 75mg drug order amoxicillin 500mg sale trimox 500mg canada
order generic cialis 5mg Buy cheap viagra online us buy sildenafil 50mg for sale
anastrozole 1 mg canada order clarithromycin 250mg generic sildenafil generic
order deltasone 5mg pill prednisone ca viagra price
tadalafil ohne rezept original sildenafil 50mg rezeptfrei sicher kaufen sildenafil 100mg kaufen
order isotretinoin without prescription accutane 10mg without prescription ivermectin 12mg stromectol
cost modafinil diamox 250mg canada acetazolamide order online
doxycycline 100mg sale furosemide 100mg pills buy furosemide 100mg without prescription
order ramipril 10mg without prescription buy temovate sale buy astelin 10ml sprayers
catapres 0.1 mg uk purchase minocycline for sale buy tiotropium bromide 9 mcg online cheap
buspar generic purchase oxybutynin without prescription order oxybutynin 5mg pills
terazosin 1mg pill order generic actos 15mg order azulfidine 500 mg generic
buy isosorbide for sale imdur cost telmisartan online
order zoloft generic order lexapro 10mg generic buy generic sildenafil
buy salbutamol 100mcg online cheap pantoprazole 20mg cost order sildenafil 50mg generic
cialis 10mg cheap cialis oral brand symmetrel
naltrexone 50mg us femara 2.5 mg uk abilify pills
dapsone 100mg generic order adalat pills buy aceon 4mg generic
order provera 5mg generic cyproheptadine 4 mg pill buy cyproheptadine online
buy generic nootropil 800mg nootropil 800 mg usa viagra 100mg drug
cheap tadalafil pills brand cialis 20mg cheap viagra sale
lasix sale buy hydroxychloroquine pill order plaquenil pills
order tadalafil pills tadalafil 5mg us anafranil online order
glycomet 500mg us purchase lipitor for sale tadalafil 5mg generic
buy olanzapine 10mg sale order diovan pills valsartan ca
amlodipine 5mg ca order sildenafil for sale cialis black
omeprazole 10mg pill help writing a paper money slots
buy lopressor generic order metoprolol online order vardenafil 20mg for sale
online thesis writing help writing paper blackjack card game
cheap essays online helpwithassignment viagra sildenafil
purchase triamcinolone pill purchase aristocort online cheap purchase desloratadine online cheap
buy zyloprim 100mg online cheap allopurinol 300mg oral ezetimibe 10mg canada
methotrexate 2.5mg pill coumadin medication order reglan 10mg generic
ozobax online order toradol over the counter buy toradol pill
order sumatriptan order generic levofloxacin 500mg generic avodart 0.5mg
purchase colchicine pill brand colchicine 0.5mg legal online blackjack
casino slot free online gambling money sports gambling free casino
metronidazole medication bactrim online buy bactrim 480mg without prescription
cheap viagra online brand sildenafil cialis for sale
buy cefuroxime 500mg for sale order ceftin pills order robaxin generic
real online casino blackjack free online buy cialis 40mg sale
write research paper for me stromectol humans buy stromectol canada
sildalis uk order sildalis for sale order lamictal 200mg for sale
order prednisone 20mg pill order amoxicillin without prescription amoxicillin price
viagra cost order tadalafil pills oral tadalafil 10mg
order zithromax generic buy prednisolone 10mg for sale buy gabapentin 600mg generic
buy sildenafil sale purchase fildena for sale order budesonide sale
generic tretinoin buy tadalis 20mg generic order avanafil 200mg generic
buy tadacip 20mg online order diclofenac 50mg generic indomethacin for sale online
lamisil pills buy amoxicillin 500mg without prescription brand trimox
spiriva 9 mcg ca hytrin 1mg without prescription purchase terazosin online
buy cialis 5mg pills casino game real money slots
where to buy cialis ed pills cialis black
buy nifedipine 10mg pill fexofenadine price cost fexofenadine 180mg
play poker online for real money cheap custom essay academic writing online
order altace for sale amaryl 4mg us cheap arcoxia
asacol 800mg uk buy irbesartan pill irbesartan 150mg uk
cost priligy 60mg buy motilium purchase motilium generic
buy tadacip generic tadacip 20mg usa purchase amoxicillin online cheap
cheap glucophage 500mg purchase verapamil for sale brand tamoxifen 20mg
clomid cost prednisolone 10mg cheap purchase prednisolone online
order isotretinoin 10mg pill buy prednisone 5mg generic purchase ampicillin pills
buy sildenafil 50mg pills erectile dysfunction propecia order
ivermectin 0.5% lotion oral stromectol 12mg buy prednisone for sale
buy accutane 10mg generic zithromax usa azithromycin 250mg us
order inderal 10mg pill brand fluconazole 200mg order carvedilol 25mg pill
order imuran online cheap imuran 25mg naprosyn 250mg price
purchase ditropan online cheap cost prograf 1mg oxcarbazepine 300mg oral