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


相关内容

热门资讯

玩家分享攻略“微信小程序掼蛋辅... 家人们!今天小编来为大家解答微信小程序掼蛋透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪...
今日重大发现“新超凡炸/金/花... 您好:新超凡炸/金/花这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在...
我来教教您“土豪赢三张辅助器?... 网上科普关于“土豪赢三张有没有挂”话题很是火热,小编也是针对土豪赢三张作*弊开挂的方法以及开挂对应的...
最新引进“麻友圈2到底有挂吗?... 家人们!今天小编来为大家解答麻友圈2透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买很...
今日重大通报“乐斗小院到底是不... 网上科普关于“乐斗小院有没有挂”话题很是火热,小编也是针对乐斗小院作*弊开挂的方法以及开挂对应的知识...
我来教教您“三鑫联盟到底有挂吗... 我来教教您“三鑫联盟到底有挂吗?”(太坑了原来有挂)您好,三鑫联盟这个游戏其实有挂的,确实是有挂的,...
重磅消息“天天微乐怎么开挂?”... 重磅消息“天天微乐怎么开挂?”(必胜开挂神器)您好,天天微乐这个游戏其实有挂的,确实是有挂的,需要了...
最新引进“顺欣茶坊是不是有挂?... 有 亲,根据资深记者爆料顺欣茶坊是可以开挂的,确实有挂(咨询软件无需打开...
个别餐饮商户感染艾滋病?辽宁喀... 关于“个别餐饮商户感染艾滋病”传言的情况通报近期,有关于“个别餐饮商户感染艾滋病”的传言,为回应社会...
今日重大发现“熊猫麻将是不是有... 家人们!今天小编来为大家解答熊猫麻将透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买很...