Mongodb:在 find() 中使用 $or 时返回匹配的过滤器 [英] Mongodb: return matched filters when using $or in find()

查看:16
本文介绍了Mongodb:在 find() 中使用 $or 时返回匹配的过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 Mongodb 中进行这样的查询

Suppose I am doing a query in Mongodb like this

db.user.find({$or : [{"field1" : "abc"}, {"field2" : "def"}, {"field3" : "ghi"}]})

并且返回了一些文档.知道每个返回的文档匹配三个过滤器中的哪一个(或多个)的最简单方法是什么?通过最简单",我不希望添加更多 find() 的执行.

And a number of documents are returned. What is the easiest way to know which one (or multiple) of the three filters is matched for each document returned? By "easiest", I do not wish to add more executions of find()'s.

谢谢.

推荐答案

MongoDB 查询层没有这样的选项可以解决这个问题.您可能希望执行单个查询而不是一个大的 $​​or 查询来解决您的问题.

There is no such option to solve this on the MongoDB query layer. Likely you want to perform individual queries instead one big $or query in order to solve your problem.

这篇关于Mongodb:在 find() 中使用 $or 时返回匹配的过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆