开发者

php mongodb find - return calculated value

开发者 https://www.devze.com 2023-03-11 10:28 出处:网络
In PHP -> MongoDB, how do I return a field as a calculated value? $this->Collection = $this->db->$theDB;

In PHP -> MongoDB, how do I return a field as a calculated value?

$this->Collection = $this->db->$theDB;  
$cursor = $this->Collection-&g开发者_开发问答t;find();

For example, one of my fields is date of birth:

DOB : 1/1/1980

Instead, I want to get back the AGE. Current Date - DOB = AGE.

Is this possible / how?


You could do a map-reduce and process the age like that


No, it is not possible.

How about just create method that will return to you age from dob?

getAgeFromDOB(date dob)
{
  return Current Date - dob;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号