Lcb_subdoc function call is not returning any error when document is not exists in couchbase

lcb_subdoc function call appends new field or updates existing field in document only if that document is present in Couchbase database, but it doesn’t return any error result when document is not exist, in both case it return LCB_SUCCESS in the result.

Code snippet which trying to append or update field in the existing document.

    char docId[DOCUMENT_ID_LENGTH+1];
    if(!CreateDocId(docId, key, parameters) || dataLen == 0)
        return FALSE;
    SDBResult result;
    lcb_subdocspecs_create(&specs, 1);
    lcb_subdocspecs_dict_upsert(specs, 0, 0 , attributeName, STRLEN(attributeName), data, dataLen);
    lcb_cmdsubdoc_key(cmd, docId, strlen(docId));
    lcb_cmdsubdoc_specs(cmd, specs);
    SetCommandParams(cmd, parameters, CMD_SUBDOC_UPSERT);
    lcb_STATUS error;
    if ((error = lcb_subdoc3(m_instance, &result, cmd)) != LCB_SUCCESS)
        SET_ERR_CODE(errCode, error);
        CLogger::Debug(__FILE__, __LINE__, "Failed to schedule writeValue operation for documentId [%s], error[%s]", docId, GetErrorDesc(error));
        return FALSE; 
    lcb_wait(m_instance, LCB_WAIT_DEFAULT);

In above case we always get for LCB_SUCCESS result.rc, irrespective of give document is present or not.
Or do we have anything that will show document is not exist when we trying to write or update subdocument?

Any help would be appreciated.

Hi @Somanath_Jagadale

Which version of libcouchbase are you using? I’m not able to reproduce this with the latest version