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
Remove nested document with condition
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
  4 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
 
SD  
View profile  
 More options Nov 15 2012, 12:22 pm
From: SD <snehadeepset...@gmail.com>
Date: Thu, 15 Nov 2012 09:22:20 -0800 (PST)
Local: Thurs, Nov 15 2012 12:22 pm
Subject: Remove nested document with condition

From the following JSON, how do I remove the dog with the least height

{
   _id:0
   "name":"Andy",
   "pets":[
      {
         "type":"dog","name":"max","height":120
      },
      {
         "type":"dog","name":"rover","height":44
      },
      {
         "type":"dog","name":"katie","height":100
      },
      {
         "type":"cat","name":"minni"
      }
   ]

}

Thanks

--SD


 
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.
Ronald Stalder  
View profile  
 More options Nov 15 2012, 1:59 pm
From: Ronald Stalder <ronals...@gmail.com>
Date: Thu, 15 Nov 2012 10:59:02 -0800 (PST)
Local: Thurs, Nov 15 2012 1:59 pm
Subject: Re: Remove nested document with condition

I can think of two possibillities:

(a) find all the documents with dogs, for each document found loop the pets
to find the lowest dog, then remove it:

(b) use aggregate or mapReduce to find the lowest dogs per _id and remove it

You can find an analog expample (for node.js) on
https://gist.github.com/4080463 (the mapReduce (2nd file) actually doesnt
remove the lowest score but you can add this to the finalize function

cheers


 
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.
Ronald Stalder  
View profile  
 More options Nov 15 2012, 2:02 pm
From: Ronald Stalder <ronals...@gmail.com>
Date: Thu, 15 Nov 2012 11:02:10 -0800 (PST)
Local: Thurs, Nov 15 2012 2:02 pm
Subject: Re: Remove nested document with condition

SORRY,

add remove to the finalize function does not work, that was stupid of me.
You'll have to loop the resulting collection of the mapReduce


 
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.
SD  
View profile  
 More options Nov 19 2012, 2:13 pm
From: SD <snehadeepset...@gmail.com>
Date: Mon, 19 Nov 2012 11:13:31 -0800 (PST)
Local: Mon, Nov 19 2012 2:13 pm
Subject: Re: Remove nested document with condition

That helps, thanks for the example.


 
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     Older topic »