nativescriptcouchbasenativescript-vuecouchbase-lite

Delete a specific dataset in a couchbase db by nativescript vue?


There is a couchbase database locally saved with cats in it. A click on a specific cat, I want to delete it from the db.

Following code is for to add a cat to db:

methods: {
    addCat() {
        let documentId = database.createDocument({
            "name": randomName(),
            "age": getRandomInt(1,10),
            "id": _uniqueId('tttbbb')
        });
        this.cats = getCats();
    },

How may I get the DocumentID from the clicked cat (record) for deleting it? Is the DocumentID automatically stored in the recordset? I could not find it, thats why I added a id.

Thanks very much for your help.

Best regards Juergen


Solution

  • While creating your object you need to set id. I found this method the easiest way to find what you are looking for to delete.

    let documentId = database.createDocument({
                    "name": randomName(),
                    "age": getRandomInt(1,10)
                },"tttbbb");
    
    createDocument(data: Object, documentId?: string): any;
    

    You will need to retrieve documentID to delete it.

    deleteDocument(documentId: string): any;