You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Trevor Green <Tr...@MAILAGC.COM> on 2011/06/17 00:01:37 UTC

How to view child arrays in couch

 

So what I want to do is store php objects in couch.

 

So 

 

Json_encode an object that may be a multi-dimensional array and store it
and the view it. 

 

The stored data would look something like this. 

 

{

                "url": "(a url)",

                "status": [{ "somename":

                                                {

"var1": "mystate",

                                                "var2":"mystate2"

}

}]

}

 

So how then do map this?

 

function(doc) {

                emit([doc.url, doc.status, doc.status.(use the first
nameas a key without explicity defining it (ex. somename) ) ], doc);

  }

}

 

Maybe use an if(doc.status.(first value) == "somename") to limit the
set?

 

How do you create views on lists like this that contain associative
arrays with arbitrary data? And how do you then access the children
(var1, var2). 

 

Can couch not handle a document like this that is valid json but isn't
flat? 

 

Or can it handle it and I have to somehow nest views to map the sub
arrays?

 

Thanks for any help.

 


Re: How to view child arrays in couch

Posted by Sean Copenhaver <se...@gmail.com>.
You might want to link out to a pastbin or gist or something. Formatting is
all screwed up for me at least.

I'm not entirely sure what you are trying to accomplish but you can emit()
multiple key/value pairs for a document. So if you were trying to be able to
query on some fields in the objects in the array, you could certainly loop
over the array and emit what you needed.

You will want to keep in mind that map() functions are defining a single
dimension index. So don't expect it to allow you to specify one long array
of keys then perform any arbitrary query you want. I don't know where your
understanding of CouchDB's map/reduce views is at but I'll include a link to
the wiki:

https://wiki.apache.org/couchdb/Introduction_to_CouchDB_views

On Thu, Jun 16, 2011 at 6:01 PM, Trevor Green <Tr...@mailagc.com> wrote:

>
>
> So what I want to do is store php objects in couch.
>
>
>
> So
>
>
>
> Json_encode an object that may be a multi-dimensional array and store it
> and the view it.
>
>
>
> The stored data would look something like this.
>
>
>
> {
>
>                "url": "(a url)",
>
>                "status": [{ "somename":
>
>                                                {
>
> "var1": "mystate",
>
>                                                "var2":"mystate2"
>
> }
>
> }]
>
> }
>
>
>
> So how then do map this?
>
>
>
> function(doc) {
>
>                emit([doc.url, doc.status, doc.status.(use the first
> nameas a key without explicity defining it (ex. somename) ) ], doc);
>
>  }
>
> }
>
>
>
> Maybe use an if(doc.status.(first value) == "somename") to limit the
> set?
>
>
>
> How do you create views on lists like this that contain associative
> arrays with arbitrary data? And how do you then access the children
> (var1, var2).
>
>
>
> Can couch not handle a document like this that is valid json but isn't
> flat?
>
>
>
> Or can it handle it and I have to somehow nest views to map the sub
> arrays?
>
>
>
> Thanks for any help.
>
>
>
>


-- 
“The limits of language are the limits of one's world. “ -Ludwig von
Wittgenstein