查询键中的MongoDB通配符 [英] MongoDB wildcard in the key of a query

查看:56
本文介绍了查询键中的MongoDB通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在查询中使用通配符?例如,给定以下记录,我想执行.find({'a.*': 4}) https://jira.mongodb.org/browse/SERVER-267 中对此进行了讨论,但看起来尚未解决.

Is it possible to wildcard the key in a query? For instance, given the following record, I'd like to do a .find({'a.*': 4}) This was discussed here https://jira.mongodb.org/browse/SERVER-267 but it looks like it's not been resolved.

{
  'a': {
    'b': [1, 2],
    'c': [3, 4]
  }
}

推荐答案

根据要求,这是不可能的.您链接到的服务器问题仍在"我们不确定的问题" 下.

As asked, this is not possible. The server issue you linked to is still under "issues we're not sure of".

MongoDB对数组的使用有一些了解,我认为这是围绕此功能的复杂性的一部分.

MongoDB has some intelligence surrounding the use of arrays, and I think that's part of the complexity surrounding such a feature.

执行以下查询db.foo.find({ 'a.b' : 4 } ).该查询将匹配以下文档.

Take the following query db.foo.find({ 'a.b' : 4 } ). This query will match the following documents.

{ a: { b: 4 } }
{ a: [ { b: 4 } ] }

那么通配符"在这里做什么? db.foo.find( { a.* : 4 } )它与第一个文档匹配吗?那第二个呢?

So what does "wildcard" do here? db.foo.find( { a.* : 4 } ) Does it match the first document? What about the second?

此外,这在语义上是什么意思?如您所述,查询实际上是查找文档,其中该文档中的任何字段的值为4" .有点不寻常.

Moreover, what does this mean semantically? As you've described, the query is effectively "find documents where any field in that document has a value of 4". That's a little unusual.

您要实现一种特定的语义吗?也许更改文档结构会为您提供所需的查询.

Is there a specific semantic that you're trying to achieve? Maybe a change in the document structure will get you the query you want.

这篇关于查询键中的MongoDB通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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