couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Benesch <ja...@realestatetomato.com>
Subject Re: a newbie question about querying an exact array field
Date Wed, 21 Jul 2010 17:34:30 GMT
Javascript doesn't allow you to compare arrays.

You'll either have to json encode or hash the array and then compare the
hashes.

On Wed, Jul 21, 2010 at 9:47 AM, Richard Llewellyn <llewelr@gmail.com>wrote:

> Hello,
>
> If I have a document with eg doc.my_array = [1,2,3,4,5]
>
> how do I query on the my_array field?
>
> I thought I could write a simple view:
>
> function(doc){
>  if (doc.my_array == [1,2,3,4,5])
> { emit(null, doc)
> }}
>
> but seems I must be missing something very basic, though I have mucho
> googled, as this returns nothing in Futon.  Or is this my ignorance of
> javascript?
>
> I see that if I have a doc with a collection field eg: doc.my_collection =
> {0:1, 1:2, 2:3, 3:4,4:5},
> I can retrieve it by converting the collection to a string
>
> function(doc){
> if (doc.my_collection) == "{0:1, 1:2, 2:3, 3:4,4:5}")
> ....
> as long as I am careful to format the string exactly right.   So I could
> store lists as collections with explicit indexes and retrieve them that
> way.
>  Is this standard practice?
>
>
> Thanks,
> Rich
>



-- 
Jason Benesch

We just launched www.TomatoUniversity.com - Join for free!
Technology Training for the Real Estate Industry.

Real Estate Tomato
Co-owner
www.realestatetomato.com
(619) 770-1950
jason@realestatetomato.com

ListingPress
Owner, Founder
www.listingpress.com
(619) 955-7465
jason@listingpress.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message