Invoking database methods in WeDa js methods
Background
Users want to invoke database queries via JavaScript directly in the WeDa editor.
Implementation Process
- Define a JavaScript method in the WeDa editor. The JavaScript code is as follows:
export default async function ({ event, data }) {
const db = (await $w.cloud.getCloudInstance()).database();
db.collection("tableName") // tableName is the corresponding collection name
.doc("dataId") // dataId is the _id of the data
.get()
.then((res) => {
console.log(res.data);
});
}
Note
$w.cloud.getCloudInstance obtains the initialized CloudBase instance in the current runtime environment

- Run the js method to print the query results
