mongodb的通配符查询的一次失败经验
admin
2023-04-13 17:01:55
0
我想find到mongo中的synonym_titles下面的嵌套子json下的影片名字段或者real_titles下面的嵌套子json下的影片名字段:


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


但是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


相关内容

热门资讯

员工用企业账号向顾客发送“有偿... “5000陪我一晚上有时间吗?”近日,贵阳一沪上阿姨门店的企业成员账号给顾客发送“有偿陪睡”信息一事...
一枚鸡蛋的价值跃升之旅(合力奋... □本报全媒体记者 陈晨 蒋晓芳 本报通讯员 范鑫 一枚普通的鸡蛋,在科技创新的加持下,能释放出多大能...
四川省省长施小琳:将“人工智能... 中新社成都5月11日电 (单鹏 程兆 王鹏)四川省省长施小琳11日在成都表示,四川将“人工智能+”作...
75个OpenAI打工人,一夜... ▲头图由AI辅助生成 智东西 编译 | 陈佳 编辑 | 漠影 智东西5月11日消息,今日,据《华尔街...
英媒披露:美国要求在格陵兰新开... 【文/观察者网 王一】美国总统特朗普仍没有放弃他对格陵兰岛的野心。据英国广播公司(BBC)5月12日...
南京审计大学一男生被曝在校内偷... 南京审计大学5月12日通报:2026年5月11日晚,有网友在网络平台反映我校某学生涉嫌偷拍他人隐私。...
告别“从摇篮到坟墓”保障?“瑞... 【文/观察者网 柳白】那个人们熟知的,以“从摇篮到坟墓”保障著称的高福利国家瑞典,正在悄然发生变化。...
以算电协同赋能新型能源体系 来源:经济日报 “十五五”时期是我国基本实现社会主义现代化夯实基础、全面发力的关键时期,也是我国加快...
原创 芯... 文/王新喜 近期,中芯国际创始人张汝京在采访中表示,认为在半导体行业取得成功就必须能够制造3nm或2...
Maximo机器人太阳能安装系... Maximo是由AES公司孵化的太阳能机器人企业,近日宣布在AES位于加州克恩县加州城附近的Bell...