Re: include_docs in Android TouchDB

30 views
Skip to first unread message

Marty Schoch

unread,
Feb 28, 2013, 10:04:26 AM2/28/13
to mobile-c...@googlegroups.com
Can you show how you're querying the view?  TouchDB-Android currently only supports including the document that emitted the row.  This means it doesn't matter what key or value you emit.  I say "currently" because CouchDB supports including linked documents (see http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views).  I'm not sure if TouchDB-iOS supports this or not.

However, based on your sample code you're only trying to include the primary document anyway, and this should work.

marty


On Wed, Feb 27, 2013 at 10:48 PM, Stefan Otto <sott...@googlemail.com> wrote:
Hello,

I'm trying to write a view for Android TouchDB that emits a document through the include_docs parameter.


in JavaScript I would write seomthing like this:

function(doc) { if(doc.type == 'comment') { emit([doc.id], {'_id': doc.entry_id}); } } }

How can I do this in Java? I tried this:

emitter.emit(document.get("id").toString(), "{_id:" + document.get(("id")) + "}");

But the ResultView rows only have the comment-documents themselves attached, instead of the referenced entry docs.

Thanks!!

--
You received this message because you are subscribed to the Google Groups "Mobile Couchbase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Stefan Otto

unread,
Mar 1, 2013, 11:20:05 AM3/1/13
to mobile-c...@googlegroups.com
No I'm not. "Entry" is another document type. The comment contains the key to the corresponding entry...

The code above is a bit reduced, because I primarily wanted to know whether the feature is implemented. Sadly it's not!

In JS my view would look like this:

function map(doc) {
    if(doc.type == comment)
        emit([doc.author], {_id: doc.entry_id})
}


I would query this view with the "include_docs" and "key" parameters to get all "entry" documents that were commented by the author (string) provided in the key.
--

A bit of background information: I'm doing a case study of NoSQL databases for embedded systems. It's a non-term job at the university and my first experience working with CouchDB/TouchDB and a document-oriented database for that matter. I'm aware that my implementation is somewhat derived from a relational approach and that I could just store the comments in the corresponding entry documents. But as I said, this is meant to be a small and easy case study to demonstrate several ways it can be done. And I guess that the "store everything in one document" wouldn't be suitable for most real-world models.
I'd appreciate your thoughts that!

Thanks!!

Marty Schoch

unread,
Mar 1, 2013, 11:24:22 AM3/1/13
to mobile-c...@googlegroups.com
In that case the feature you want is not implemented.  Currently in TouchDB-Android you can only include the document that emitted the row, not any other document.

You should open an issue for this on the github repo.  On the surface it doesn't seem like it would be hard to implement, it is essentially a query-time lookup of a document by id, and merging it into the view output.  But I haven't looked to see how the iOS version does it.  Patches would definitely be welcome here.

marty
Reply all
Reply to author
Forward
0 new messages