Updating a document to increment view counts (such as how many times a forum topic has been viewed,) should this be done by directly updating the document with the incremented value? Reason I ask is performance impact and if values would get overlapped in a high traffic environment (causing values not to be accurately tracked/incremented.)
Also, does updating a document take longer to update the larger its data becomes? Having a few million documents in a bucket is annoying, would be nice to put repetitive data in a document (such as multiple days of traffic data for a site in a single document rather than spread across multiple documents.)
Hopefully my post makes sense. Thanks for any insight.
Hey, for the use case you describe, you could consider using an atomic counter. If you’re in Java, for example, here’s the SDK guide page for atomic counters:
http://docs.couchbase.com/developer/java-2.1/documents-atomic.html
With atomic counters the increment/decrement happens on the Couchbase side, rather than having you pull out a document, edit it in the application layer, and then write it back in.
If, for example, your forum topic had a key name of f::123456, you could then use a predictable key naming pattern so the counter would be a f::123456::counter or similar.
Larger documents do take longer to update, primarily due to the time it takes to transfer them over the network. There’s an upper-limit of 20MB on Couchbase documents for that reason, but in most cases you’ll want to keep your documents well below that.
Couchbase is designed for millions of documents, rather than a few very large documents.
Thanks.