php mongodb find - 返回计算值

发布于 2024-11-13 05:49:58 字数 279 浏览 5 评论 0原文

在 PHP 中 -> MongoDB,如何返回字段作为计算值?

$this->Collection = $this->db->$theDB;  
$cursor = $this->Collection->find();

例如,我的字段之一是出生日期:

DOB : 1/1/1980

相反,我想取回 AGE。当前日期 - 出生日期 = 年龄。

这可能/如何?

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

$this->Collection = $this->db->$theDB;  
$cursor = $this->Collection->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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三五鸿雁 2024-11-20 05:49:58

您可以执行 map-reduce 并像这样处理年龄

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

权谋诡计 2024-11-20 05:49:58

不,这是不可能的。

只创建一个从 dob 返回你年龄的方法怎么样?

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文