Necessary to emit document in MAPBLOCK

18 views
Skip to first unread message

Ragu Vijaykumar

unread,
Apr 21, 2014, 8:08:16 PM4/21/14
to mobile-c...@googlegroups.com
I just noticed that CBLQueryRow has a document property that returns a CBLDocument. If this is the case, when we write our MAPBLOCKs, is it necessary to emit the doc that is passed in? Can I just access that document via the QueryRow.document property?

Jens Alfke

unread,
Apr 21, 2014, 8:26:14 PM4/21/14
to mobile-c...@googlegroups.com

On Apr 21, 2014, at 5:08 PM, Ragu Vijaykumar <ra...@scrxpt.com> wrote:

I just noticed that CBLQueryRow has a document property that returns a CBLDocument. If this is the case, when we write our MAPBLOCKs, is it necessary to emit the doc that is passed in? Can I just access that document via the QueryRow.document property?

Emitting the document as the value is strongly discouraged. It’s not necessary, as you’ve seen, and it can greatly slow down indexing because of the extra JSON conversions. In general you should only emit the values you need for your queries. If you don’t need values, or if you just want to grab the documents, emit nil for the value.

(The reason some people do it is because accessing the document via the query row value is slightly faster than fetching the document from the database. But the difference is minor, and you pay for it with slower indexing, which can be a real pain point in Couchbase Lite.)

—Jens

Ragu Vijaykumar

unread,
Apr 22, 2014, 12:09:22 AM4/22/14
to mobile-c...@googlegroups.com
Whoa, so glad I asked because that is exactly what I was worried about (slow indexing because I know my documents are large). Thank you for that information and guidance.

FYI, it seems like the examples in your online documentation do this, which is where I got the idea. Would be very helpful if your comments were put in the documentation for others, e.g. what are appropriate key/values, what is grouplevel and how it works, etc.

Cheers,
Ragu

Jens Alfke

unread,
Apr 22, 2014, 10:00:26 AM4/22/14
to mobile-c...@googlegroups.com
On Apr 21, 2014, at 9:09 PM, Ragu Vijaykumar <ra...@scrxpt.com> wrote:

FYI, it seems like the examples in your online documentation do this, which is where I got the idea.

Good to know — we’re updating the docs for the 1.0 release and I’ll let the other team members know to look out for examples that use this anti-pattern.

Would be very helpful if your comments were put in the documentation for others, e.g. what are appropriate key/values, what is grouplevel and how it works, etc.

The rewritten view/query docs address these and other points.

(To answer the next question, the new docs aren’t ready yet but will be released along with the 1.0 software in a few weeks.)

—Jens
Reply all
Reply to author
Forward
0 new messages