RT···用mongo记录日志体验下,发现并不像想象中那么顺畅
使用mongo的document对象存数数据,结构如下
{
"_id" : "567d05ded569dbc10c0041b2",
"order_id" : "1234",
}
然后在model的search方法里面写如下
- public function search()
- {
- // @todo Please modify the following code to remove attributes that should not be searched.
- $criteria = new EMongoCriteria();
- $criteria->compare('order_id', $this->order_id);
- return new EMongoDataProvider($this, array(
- 'criteria'=>$criteria,
- ));
- }
- elseif(preg_match('/^(?:\s*(<>|<=|>=|<|>|=))?(.*)$/', $value, $matches)){
- $value = $matches[2];
- $op = $matches[1];
- if($partialMatch === true){
- $value = new MongoRegex("/$value/i");
- }else{
- ///* preg_match() Will only match real integers, unsigned */
- // /* If it is a 64 bit system and the value is under the long max */
- // /* value is under 32bit limit */
- if(!is_bool($value) && !is_array($value) && preg_match('/^([0-9]|[1-9]{1}\d+)$/', $value) > 0
- && ((PHP_INT_MAX > 2147483647 && (string)$value < '9223372036854775807') || (string)$value < '2147483647')){
- $value = (int)$value;
- }
- }
犹豫拍板问题我把注释改造了下,大家可以看到 order_id 走到了
- if(!is_bool($value) && !is_array($value) && p。。。。。这里 被强制转换成int了,而PHP中一般不会特别注意数据类型,order_id在插入的时候就写为了string类型,所以查不到,然后上面加个is_string方法即可。。以后空了在慢慢修改这个源码
- 扩展地址为https://github.com/Sammaye/MongoYii.git
PS:删除的无法恢复了。先凑合着。发现save()的时候保存的是字符串,但是查询order_id的时候类型是int,还是根据实际情况修改源码吧。建议插入的时候就做处理,我没做处理,只能在查询上做文章了。