couchbaseClient.delete returns always status message 'NotFound'

I’m trying to implement a restore of the couchbase-lite database locally on the iOS device.
For this, I have to get rid of all documents stored on the server - including any tombstone revisions.

That said, I’m trying now to implement a delete all method on the server side which uses cfCouchbase for accessing the buckets data of a given channel.
As you can see here: Google Groups the deletion of a document always returns a status message of ‘NotFound’

Do you have any idea why?

Are you trying to delete individual documents, or “flush” the entire bucket? Based on the thread you linked to, it sounds like the latter is what you’re going for. Firstly, make sure flush is enabled in the settings for that bucket. Secondly, flushing is async and can take a long time before it completes internally. Until its done, views will have out of sync data in them and the data in the buckets might behave out of sync. I’ve found it can take a few minutes before a flush is finished and the buckets start operating normally again. Since flush is an admin feature, there is no way to execute it in a manner in which it will block until the operation is complete.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad,

Thanks for getting back in this. Unfortunately I'm not trying to flush the bucket.

Instead I'd like to delete all documents of a given user from the bucket.

So flushing the bucket isn't going to work :frowning:

So, are you executing a view to get a current list of documents, then looping over that list and deleting each one?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Exactly. Any Ideas why those documents are "NotFound"?

Nope. Can you confirm which version of the SDK you’re using? Also, if you dump out the name of the document being deleted right as it’s passed into the Java calls, does it match exactly (case sensitive) with the document name in the Couchbase web admin?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

I’m using the cfcouchbase-sdk v1.1.1, which contains the couchbase-client-1.3.1.jar
And I’ve added a view with the following code:

`

function(doc,meta){
if( !doc._deleted && doc.channels && doc.channels.length && doc.type != ‘Setting’ ){
for( var i = 0; i < doc.channels.length; i++ ){
emit(doc.channels[i],doc);
}
}
}

`

which returns an array containing the following coldfusion structures:

{ DOCUMENT = '', ID = '--2szFNTpPIAxX1X68LZo3u', KEY = '9c0bb124365c49d48e5e0c5577f0000d', VALUE = '{"_sync":{"rev":"2-be773aa928134657f796ce90a02caaf1","sequence":34678,"recent_sequences":[34611,34678],"history":{"revs":["1-575fde964b77a7e916f7b3f395acb4e6","2-be773aa928134657f796ce90a02caaf1"],"parents":[-1,0],"channels":[["9c0bb124365c49d48e5e0c5577f0000d"],["9c0bb124365c49d48e5e0c5577f0000d"]]},"channels":{"9c0bb124365c49d48e5e0c5577f0000d":null},"time_saved":"2015-11-24T21:38:46.558978545+01:00"},"channels":["9c0bb124365c49d48e5e0c5577f0000d"],"type":"CostCenter","value":"Marketing"}' }

I’m passing then the ID of the structure 1:1 to the delete function, resulting in the “NotFound” :frowning:
Any idea what’s wrong?

@Brad Wood:
Any Ideas?

No, not really. You’ll need to debug what’s going on your end. Can you confirm that the ID coming back from that view is a document key. Also note, views are not guaranteed to be consistent so it is possible a view might return a document for a few seconds after the it has been deleted. Can you find out for sure if the doc IDs you are trying to delete actually exist?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Ok - after A LOT of trial an error I’ve finally figured out was causing the error.

cfCouchbase internally normalizes the passed in document IDs. That said it makes sure the IDs are trimmed and all lowercase.
In my case this has caused couchbase server to simply not find the document.

If you have a look at the following line in the couchbaseClient.cfc you’ll notice the normalizeID call:

`

any function delete(
required any ID,
string persistTo,
string replicateTo
){
arguments.ID = variables.util.normalizeID( arguments.ID );

`

After commenting the line arguments.ID = variables.util.normalizeID( arguments.ID ); everything started working!

Question remains: Why the hell cfCouchbase does modify the passed in IDs?

Ahh yes, I should have thought of that. The CFML Couchbase SDK doesn’t enforce case-sensitivity because CFML is inherently a case-insensitive language and we wanted the following code to work:

client.set( ‘Foo’ );
client.get( ‘foo’ );

That is consistent with CF variables, as well as how ColdFusion handles functions like cacheGet() and cachePut().

As long as you’re using the SDK to create all your documents, you shouldn’t have an issue. If you’re creating keys directly in the buckets outside of the CFCouchbase SDK, then you’d need to get the underlying Java object with getCouchbaseClient() and call the native method to delete a document.

Perhaps has an enhancement we can add a feature toggle to disable case-sensitivity for people needing to manage documents created directly in the server.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com