couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Metson <>
Subject Re: Merge Documents
Date Thu, 18 Nov 2010 08:32:52 GMT

> Its simple to find all the numbers that are used by creating a view  
> of all
> the Number with Type = Person.
> But, how do I find all the numbers that aren't being used yet?
> I can pull up the view of all the numbers and compare those with the  
> used
> numbers on client side, but I prefer not to.

How about a view like:

function(doc) {
   if (doc.type == 'Number') {
     emit(doc.Number, 1);
   if (doc.type == 'Person') {
     emit(doc.Number, -1);

with a _sum reduce, query that view with ?group=true then client side  
take out values that are greater than 0 using array.filter:

js> function unused(element, index, array){
   return element.value > 0;
js> data.rows.filter(unused)
[object Object],[object Object],[object Object],[object Object], 
[object Object]...

The size of the array you have to filter will always be the number of  
Number documents, so you can have lots of People in the database but  
have a known size of json to filter client side.

I can't think of a way to do it with a view slice, possibly because  
I've not had my morning coffee yet...
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message