create documents with unique keys with php memcached
Tue, 12/27/2011 - 16:45
In the documentation it is shown that you can create multiple documents with the same key and not override them like this:
<?php // setup skipped $cb->set('a', '{"name": "Simon"}'); $cb->set('a', '{"name": "Ben"}'); $cb->set('a', '{"name": "James"}');
After this I should create a view and get a list of all these persons. In the browser couchbase console I can see only "James". It seems that this document was written and overwritten three times. How can I create documents with unique CouchDB keys?
I am running ubuntu 10.10 64bit, php 5.3, PHP SDK: Ubuntu 9.04, 64-bit (10.x compatible, Debian compatible).
Since you're overwriting the same key/_id multiple times [each invocation of the set() has the same 'a' for the key] you're replacing Simon and Ben with James. Things are behaving correctly. Instead, you should try
$cb->set('a', '{"name": "Simon"}');
$cb->set('b', '{"name": "Ben"}');
$cb->set('c', '{"name": "James"}');
That'll create three documents, all should be in the view.