Skip to main content

Delete the data.

In this section, we continue to use the data from the reading data chapter as an example.

Delete a record

The remove() method deletes a record.

Note

On the client side, only data with proper permissions can be deleted. For details, refer to Access Control.

Sample code as follows:

const cloudbase = require("@cloudbase/js-sdk");
const app = cloudbase.init({
env: "xxxx"
});
var db = app.database();

db.collection("todos")
.doc("doc-id")
.remove()
.then((res) => {
console.log(res);
});

Delete multiple records

To delete multiple data records, use the where statement to select the records and then delete them.

Sample code as follows:

const cloudbase = require("@cloudbase/js-sdk");
const app = cloudbase.init({
env: "xxxx"
});
var db = app.database();

db.collection("todos")
.where({
done: true
})
.remove()
.then((res) => {
console.log(res);
});