Re: View to find someone in a list in a document

2009-09-03 Thread Adam Wolff
One more little thing: per spec, for...in enumerates the array keys as strings. A On Thu, Sep 3, 2009 at 8:29 AM, Jesse Hallett wrote: > According to Crockford `for in` gives no guarantee that it will iterate > over > array elements in order. That is in addition to the problem that it will > al

Re: View to find someone in a list in a document

2009-09-03 Thread Jesse Hallett
According to Crockford `for in` gives no guarantee that it will iterate over array elements in order. That is in addition to the problem that it will also enumerate any attributes on `Array.prototype`. So Crockford recommends using `for` with an incrementing index variable instead. In my opinion

Re: View to find someone in a list in a document

2009-09-03 Thread Jan Lehnardt
On 3 Sep 2009, at 11:11, Simon Metson wrote: Hi, I'm not sure if there's a technical benefit of this syntax, but I think I prefer reading it... Any JS wizards out there like to comment? to get for(... in .. ) right you need to add: a hasOwnProperty() call to account for prototypical inher

Re: View to find someone in a list in a document

2009-09-03 Thread Simon Metson
Hi, I'm not sure if there's a technical benefit of this syntax, but I think I prefer reading it... Any JS wizards out there like to comment? Cheers Simon On 3 Sep 2009, at 09:53, Nils Breunese wrote: I even learned that using for (... in ...) is not safe for use with arrays. I tend to use

RE: View to find someone in a list in a document

2009-09-03 Thread Nils Breunese
user@couchdb.apache.org Onderwerp: Re: View to find someone in a list in a document Style police! On 2 Sep 2009, at 19:00, Simon Metson wrote: > Hi, > Do you mean you want to emit each user as a key? Something like: > > function(doc) { for (v in doc.users) { emit(doc.users[v], doc); } is

Re: View to find someone in a list in a document

2009-09-02 Thread Jehan Bihin
Thanks guys for your help ! :) 2009/9/2 Simon Metson > Hey Jan, > > function(doc) { for (var v in doc.users) { emit(doc.users[v], doc); } >> >> if you leave out the `var` you create a global variable (as opposed to a >> local variable in JS and that can have funky effects. >> > > What he said.

Re: View to find someone in a list in a document

2009-09-02 Thread Simon Metson
Hey Jan, function(doc) { for (var v in doc.users) { emit(doc.users[v], doc); } if you leave out the `var` you create a global variable (as opposed to a local variable in JS and that can have funky effects. What he said. function(doc) { if(doc.users) { for (var v in doc.users) { emit(doc.

Re: View to find someone in a list in a document

2009-09-02 Thread Jan Lehnardt
Style police! On 2 Sep 2009, at 19:00, Simon Metson wrote: Hi, Do you mean you want to emit each user as a key? Something like: function(doc) { for (v in doc.users) { emit(doc.users[v], doc); } is better written as function(doc) { for (var v in doc.users) { emit(doc.users[v], doc);

Re: View to find someone in a list in a document

2009-09-02 Thread Jehan Bihin
Thanks a lot ! I'll try it. 2009/9/2 Simon Metson > Ok, so use that map function and query it as: > > http://localhost:5984/test/_design/users/_view/user?key= > > That will give you back all the documents that have in the > users list. > Cheers > Simon > > > > On 2 Sep 2009, at 18:12, Jehan Bi

Re: View to find someone in a list in a document

2009-09-02 Thread Simon Metson
Ok, so use that map function and query it as: http://localhost:5984/test/_design/users/_view/user?key= That will give you back all the documents that have in the users list. Cheers Simon On 2 Sep 2009, at 18:12, Jehan Bihin wrote: Hi Simon, Thanks for your help. I need the document if

Re: View to find someone in a list in a document

2009-09-02 Thread Jehan Bihin
Hi Simon, Thanks for your help. I need the document if the key is present in the list. Thanks, Jehan 2009/9/2 Simon Metson > Hi, >Do you mean you want to emit each user as a key? Something like: > > function(doc) { for (v in doc.users) { emit(doc.users[v], doc); } > > as a map would

Re: View to find someone in a list in a document

2009-09-02 Thread Simon Metson
Hi, Do you mean you want to emit each user as a key? Something like: function(doc) { for (v in doc.users) { emit(doc.users[v], doc); } as a map would do that. Cheers Simon On 2 Sep 2009, at 17:25, Jehan Bihin wrote: Hi all, (sorry for my english) I have a document having a list of pe

View to find someone in a list in a document

2009-09-02 Thread Jehan Bihin
Hi all, (sorry for my english) I have a document having a list of persons : ... "users":{"membre-joouul_hotmail.com":["createur"],"membre-killan_daaboo.net ":["moderateur"]} ... Each persons have some roles. My key is the membre like 'membre-joouul_hotmail.com' And i want to list all document ha