How to reference nested JSON objects with PouchDB / BackbonePouch and Underscore.js Templates

889 views
Skip to first unread message

Bernd

unread,
Jun 10, 2013, 1:09:50 PM6/10/13
to pou...@googlegroups.com
Hi all,

I'm relatively new to CouchDB and PouchDB and App Development in general.
I have started to implement a project as a learning effect and decided after testing different technologies to use a combination of PouchDB / CouchDB.

For the beginning the replicaton to CouchDB is not essential. But I really like this feature.

So right now I have the following setup:

- PouchDB
- BackbonePouch
- Backbone.js
- Underscore.js (especially used to render the HTML code)
- Cordova / Phonegap to deploy on IOS, later maybe Android

I could setup the database and also access the documents via a map query.

Now I'm struggling to reference to the result of the map/reduce query.
It's easy as long as I reference to the first hierarchy like (e.g.: "_id", "name_attribute").

But as soon as I'd like to reference on nested objects it's starting to get tricky. In my data model I have something like 
"transactions": 
sometransactionid: { 
"name":"Some name", 
"value": 12.23
 }, 
othertransactionid: { 
"name":"Other name", 
"value": 12.23
 } 

}

I use a incremental query to emit each transaction as a key / value pair.
The question is now, how do I reference on this values.

If I understand PouchDB correctly in a "normal" map/reduce query the document is attached to the result and all names of a underscore template directly match to the doc, instead of the key /value pairs.

Do I have here a misunderstanding? How could I solve this problem?

Thanks in advance for your help!

Bernd

Johannes J. Schmidt

unread,
Jun 11, 2013, 4:24:25 PM6/11/13
to pou...@googlegroups.com
Hi Bernd,

welcome abord!

When emitting a value on a view, backbone-pouch does not use that value
but uses the doc until you are specifying include_docs to false:
query: {
include_docs: false
}

The Backbone collection will then be populated with your emitted value,
which should be an object.

If this does not help, feel free to open an issue at
https://github.com/jo/backbone-pouch/issues.

Greetings,
Johannes
> --
> You received this message because you are subscribed to the Google
> Groups "PouchDB" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pouchdb+u...@googlegroups.com.
> To post to this group, send email to pou...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pouchdb/02a39b84-3167-440e-878c-a1f56fa62507%40googlegroups.com?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages