【问题标题】:to compare two fields of the same collection比较同一集合的两个字段
【发布时间】:2013-10-29 14:44:55
【问题描述】:

我想用 cakephp 在 mongodb 中比较同一个集合的两个字段(Mysql 查询示例“SELECT * FROM table AS t WHERE t.field1 > t.filed2;”)。我不能使用 '$where' 和 mongodb 的聚合,因为我也在使用 mongodb 的其他运算符,如 $or、$and 等。而且我正在使用 mongodb 的 find。

例如:集合有两个字段整数字段 per_day_budget 和 today_spent,我想获取 today_spent 小于或等于 per_day_budget 的记录列表。我希望这会让您更好地理解我的查询。

请提出相同的解决方案。

【问题讨论】:

  • 如果可能,请在您的问题中提供您的文档示例??
  • 例如:集合有两个字段整数字段 per_day_budget 和 today_spent,我想获取 today_spent 小于或等于 per_day_budget 的记录列表。我希望这会让您更好地理解我的查询。

标签: mongodb cakephp


【解决方案1】:

你可以试试:

 db.collection.find({ this.today_spent : {$lte : this.per_day_budget}});

【讨论】:

  • 您的回答非常有帮助,但以下内容对我们有用...感谢您的支持.. db.collection.find( {"size":"300_250","$and":[{"status ":3},{"$or":[{"timelimit":"2"},{"$where":"this.today_spent
猜你喜欢
  • 2021-01-21
  • 2021-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-18
  • 2023-02-25
  • 2012-02-03
  • 1970-01-01
相关资源
最近更新 更多