Reputation: 11
I am evaluating couchdb for a persistent cart functionality. If I create one docuemnt per user and have each cart item as a field, how many items can I store? In current scenario I can have upto 500 items in a cart.
Upvotes: 1
Views: 371
Reputation: 4631
doc-per-cart or a doc-per-item are both fine choices, neither document sounds like it would get very large (JSON encoding/decoding is slower for very large documents and they must be held entirely in memory). On balance, I'd prefer doc-per-item. Of course, you will need to create a (simple) view to display the cart if you went with doc-per-item.
One good reason to prefer doc-per-item is CouchDB's MVCC. Adding an item to a cart will always create a new document, so you will not need to know the current _rev of the item. When a user wants to delete an item, you will have the _id and the _rev and can easily delete it. If you went with doc-per-cart then you will be constantly updating a document, which requires you to have the current _rev all the time.
Note that doc-per-item will allow duplicates in your cart (the user hits Reload and makes two additions instead of one) but as long as the display of the cart shows this, and the final checkout page does too, then I think it's a reasonable failure mode.
Upvotes: 2
Reputation: 2556
A quick review of the CouchDB overview should make it clear that there is no inherent limit on the number of fields in a CouchDB document, and therefore no limit (aside from available memory) to the number of items you can store in your cart.
Upvotes: 1