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 value
ais a JSON object. That JSON object has two keys
band
c. The value of those keys are 4 & 2 respectively. When you are asking for
a.*, 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