Calling Cloud Database Methods in WeDa JavaScript Methods
Background
Users want to directly call cloud database queries using JavaScript in the WeDa editor.
Implementation Process
- Define a js method in the WeDa editor. The 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 record
.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 and print the query results