Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including documents in the emit compared to include_docs = true in CouchDB

Tags:

couchdb

I ran across a mention somewhere that doing an emit(key, doc) will increase the amount of time an index takes to build (or something to that effect).

Is there any merit to it, and is there any reason not to just always do emit(key, null) and then include_docs = true?

like image 988
kolosy Avatar asked Sep 25 '09 03:09

kolosy


People also ask

What is emit CouchDB?

The emit(key, value) function creates an entry in our view result . One more thing: the emit() function can be called multiple times in the map function to create multiple entries in the view results from a single document, but we are not doing that yet.

What are the primary benefits of implementing views in CouchDB?

CouchDB uses views as the primary tool for running queries and creating reports from stored document files. Views allow you to filter documents to find information relevant to a particular database process.


1 Answers

Yes, it will increase the size of your index, because CouchDB effectively copies the entire document in those cases. For cases in which you can, use include_docs=true.

There is, however, a race condition to be aware of when using this that is mentioned in the wiki. It is possible, during the time between reading the view data and fetching the document, that said document has changed (or has been deleted, in which case _deleted will be true). This is documented here under "Querying Options".

like image 80
Ryan Duffield Avatar answered Nov 07 '22 16:11

Ryan Duffield