Thursday 15 August 2013

nested field query for mongodb (using ruby) -


Sup, good people on the internet.

Do anyone know how to create a nested query for Mangode? This is probably explained by an example. To retrieve a specific field, I can use the field option to retrieve that field (for example it is called "useful_field"):

  collection. Find ({}, {: fields = & gt; {/ Useful_field} = & gt; 1}})   

But it seems that useful_field has an array of many other areas, that is

  useful_field = ["Value_I_want" => "Useful", "value_I_dont_want" = & gt; "Not_useful"}]   

Any idea to select "value_I_want" is my purpose?

Here is a specific entry I'm trying to deal with (reply to a tweet):

  {"_id": ObjectId ("51b6f71b0364718d71e4bca5"), " "Result": "tweet", "score": 1, "groupname": "conversion with tweets", "result": [["type": "tweet", "score": 1 , "Id": Number Long ("343091955196104704"), "Annotation": {"Conversation Roll": "Ancestor"}, "Value": {"created_at": "Venus Jun 07 19:47:51 +0000 2013" , "Id": "id_str": "343091955196104704", "text": "THIS_IS_WHAT_I_WANT", etc. (Apologies for strange formatting)   

I am trying to use a method of that form to let me do something like this:

  db .collection.find ({}, {: fields {some_way_of_selecting (THIS_IS_WHAT_I_WANT)})   

(I 'query' as part of a Ruby script)

Otherwise, I would have to go back to the dark world of regex. Nobody wants to do this.

try the following

  db Collection.find ({}, {"Useful_field.value_I_want": 1})   

Perhaps try this:

  db.collection.find ({"ResultType": "Tweet"}, {"result": {$ elemMatch: {"value.text": "THIS_IS_WHAT_I_WANT"}}})    

No comments:

Post a Comment