Resolution: considerations when using phpmongodb extension. Recently, php's mongo extension was used for data statistics and computation. one of the timestamp fields, accurate to milliseconds, has 13 characters in length, however, at the beginning, data statistics were calculated using the php mongo extension in the form of a string. one of the timestamp fields is accurate to milliseconds and has a length of 13 characters, however, since it was stored as a string at the beginning:
The code is as follows:
{"_ Id": ObjectId ("504eea97e4b023cf38e34039"), "in_ts": NumberLong ("1347349143699"), "log": {"guid": "success ", "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}
Later it was changed to the numeric format:
The code is as follows:
{"_ Id": ObjectId ("504eea97e4b023cf38e34039"), "in_ts": NumberLong ("1347349143699"), "log": {"guid": "success ", "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}
It is normal to use the following query when it is a string
The code is as follows:
$ Query = array ('log. stamp' => array ('$ gte' => '000000',' $ lt '=> '000000 '));
After changing to a number, you can use the following query to check whether there is any result. However, you can directly query the result on the mongo client:
The code is as follows:
Db. haozu_success.find ({'log. stamp': {$ gte: 1347346800000, $ lt: 1347350400000 }})
This is also the usage in the php manual:
The code is as follows:
$ Query = array ('log. stamp' => array ('$ gte' => 1347346800000,' $ lt '=> 1347350400000 ));
It took a long time to find out the cause. at first, I suspected it was caused by a bug in php extension. after some thought. Suddenly it may be caused by a type problem, and Types is introduced in the manual, so the correct usage is as follows:
The code is as follows:
$ Query = array ('log. stamp '=> array (' $ gte' => new custom Int64 ($ time_range ['start']), '$ lt' => new bytes Int64 ($ time_range ['end']);
In addition, when using mapreduce for data statistics, to prevent cursor from timeout exceptions, you also need to set the timeout time.
The code is as follows:
$ Map = new response code ('
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 response code ('
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-> sort _db-> command (array ('mapreduce' => $ collection_name, 'map' => $ map, 'reduce' => $ reduce, 'Out' => $ tmp_result, 'query' => $ query), array ('timeout' => self: pai_cursor_timeout ));
The token extension is used for statistical calculation of data. one of the timestamp fields is accurate to milliseconds and has a length of 13 bits. However, the start time is in the form of a string...