千家信息网

mongodb的通配符查询的一次失败经验

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,我想find到mongo中的synonym_titles下面的嵌套子json下的影片名字段或者real_titles下面的嵌套子json下的影片名字段:但是1,2这个info信息字段不确定所以我想这么
千家信息网最后更新 2026年11月01日mongodb的通配符查询的一次失败经验我想find到mongo中的synonym_titles下面的嵌套子json下的影片名字段或者real_titles下面的嵌套子json下的影片名字段:



但是1,2这个info信息字段不确定所以我想这么查询:db.search_correct_synonym.find({"synonym_titles.*":"联邦调查局"})但是失败了,这种查询是告诉mongo,我想找到无论哪一个field,只要包含value=联邦调查局的field

最后的办法,想要找到指定的片名,可以把这些片名copy出来放到一个独立的field里,比如all_titles:["联邦调查局", "帅哥在一九二五"],可以对该字段建索引。这样就能根据db.search_correct_synonym.find({"all_titles":"联邦调查局"})找到了

详见http://stackoverflow.com/questions/6179871/mongodb-wildcard-in-the-key-of-a-query

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

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

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

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

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

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.








thanks, that clarifies. More specifically, what I'm looking to do is wildcard just the specific node in the branch, i.e. any proper subfield of a. I'm not clear on how a.* says 'find where any field'. Isn't it 'find documents that have a top-level field 'a' with a subfield that matches 4'? - BradJun 1 '11 at 5:48

I think the confusion here is around "subfield". When I write{a:{b:4,c:2}}, I am saying that the valueais a JSON object. That JSON object has two keysbandc. The value of those keys are 4 & 2 respectively. When you are asking fora.*, you're effectively asking for syntax that loops through all of the keys in that JSON object. Your're not asking to"loop through an array", you're asking to"loop through an object's properties". That's a little unusual, which is why I'm asking for a specific use case here. - Gates VPJun 1 '11 at 17:15

@gates: I have a use case. myDocInMongo = {'someUnknownKey':{propToCheck:true}, 'someKnownKey':true}; Now, I want to find this document using the selector {someKnownKey:{$exists:true}} but i also want to make sure that none of the other keys have an object with the property propToCheck. So, like the following: {'*.propToCheck':{$exists:false}, {someKnownKey:{$exists:true}}} - doubletapMay 3 '12 at 17:57


联邦 调查局 联邦调查局 查询 名字 套子 字段 影片 片名 面的 信息 办法 帅哥 索引 a. i.e. 独立 经验 通配符 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广州为想互联网科技有限公司 互联网科技有限公司经营范围 广州互联网科技公司 互联网科技的发展 互联网金融 科技金融 北京互联网络科技有限公司 互联网金融科技创新 互联网金融科技平台 丰台科技园 互联网 互联网科技大会 联恩商钥互联网科技有限公司 互联网公司会议桌创意科技软装饰 科技与互联网的利与弊 须眉科技是互联网公司吗 伍佰万互联网科技怎么赚钱 萌小萌互联网科技河南有限公司 安徽零酒互联网科技有限公司 互联网对科技影响 承德科技产业互联网平台 银川新华互联网科技学校招聘 深圳恒合互联网络科技有限公司 重庆互联网络科技 互联网企业和科技型企业 金融科技与互联网金融相同和不同 茂名市互联网科技产业园 深圳育鹏互联网科技有限公司招聘 烟台灵鸽互联网科技有限公司 上海创道互联网络科技有限公司 吉林省码上互联网科技电话 三亚科技创新互联网基地
0