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

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

问题描述

假设我在Mongodb中做这样的查询

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

并返回一些文件。什么是最简单的方法来知道三个过滤器中的哪一个(或多个)匹配每个文档返回? 最简单,我不希望增加更多的执行find()的。
$ b

谢谢。

解决方案

在MongoDB查询图层上没有这样的选项来解决这个问题。可能你想要执行个别查询,而不是一个大$或查询,以解决您的问题。


Suppose I am doing a query in Mongodb like this

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

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.

Thanks.

解决方案

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()时返回匹配的过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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