Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to express a query to match elements of a subdocument?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Russell Bateman  
View profile   Translate to Translated (View Original)
 More options Aug 18 2012, 12:12 pm
From: Russell Bateman <r...@windofkeltia.com>
Date: Sat, 18 Aug 2012 10:12:15 -0600
Local: Sat, Aug 18 2012 12:12 pm
Subject: How to express a query to match elements of a subdocument?

I have a representative collection to illustrate what I want to be able
to match, that is, a subdocument within a larger document containing a
random list of tuples (fieldname "data" below) a subset of which I want
to match (i.e.: $eq, if that were possible) to cause the (whole)
document to be returned from the query.

    >  db.tuples.findOne();
    {
         "_id" : ObjectId("502fb6a9674c381db9e9249a"),
         "rats" : "very large mice",
         "x" : 1,
         "data" : {
    "this" : "uh-huh",
    "that" : "oh-oh",
    "other" : "poo-poo-pee-doo"
         }
    }

I'm not trying to get back just the subdocument or anything weird like
that, I want the whole document back when one or more tuples I specify
match exactly in the subdocument.

Stabbing around, I find nothing working from what I know how to express:
I haven't hit upon the right query yet. Googling for examples has so far
not turned anything up. The favorite examples that come close always
appear to be arrays and not "subdocuments". The array thing just doesn't
work.

Two examples so far about which Mongo hasn't complained are below, but
they do not match.

    > db.tuples.find( {  "data" : { "this":"uh-huh", "that":"oh-oh" } } );
    >  db.tuples.find( { $and : [ { "data" : { "this":"uh-huh" } }, {
    "data" : { "that":"oh-oh" } } ] } );

Profuse thanks for any help, direction, nudges, etc.,

Russ Bateman


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Reno Reckling  
View profile   Translate to Translated (View Original)
 More options Aug 18 2012, 12:13 pm
From: Reno Reckling <exi+goo...@wthack.de>
Date: Sat, 18 Aug 2012 18:13:27 +0200
Local: Sat, Aug 18 2012 12:13 pm
Subject: Re: [mongodb-user] How to express a query to match elements of a subdocument?
On 08/18/2012 06:12 PM, Russell Bateman wrote:>

> Two examples so far about which Mongo hasn't complained are below, but they do not match.

>     > db.tuples.find( { "data" : { "this":"uh-huh", "that":"oh-oh" } } );
>     > db.tuples.find( { $and : [ { "data" : { "this":"uh-huh" } }, { "data" : { "that":"oh-oh" } }
] } );

> Profuse thanks for any help, direction, nudges, etc.,

Hi,
try
db.tuples.find( { "data.this":"uh-huh", "data.that":"oh-oh"} );
db.tuples.find( { $and : [ { "data.this":"uh-huh" }, { "data.that":"oh-oh" } ] } );

Regards,
Reno


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Bateman  
View profile   Translate to Translated (View Original)
 More options Aug 18 2012, 12:19 pm
From: Russell Bateman <r...@windofkeltia.com>
Date: Sat, 18 Aug 2012 10:19:50 -0600
Local: Sat, Aug 18 2012 12:19 pm
Subject: Re: [mongodb-user] How to express a query to match elements of a subdocument?
Ooh, thanks for the quick reply. Yes, it works. I'm always so thrown off
by the dotted notation thing. This experience just may clench it for me.

Many thanks!

On 8/18/2012 10:13 AM, Reno Reckling wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic