当前位置:网站首页>小程序通过云函数操作数据库【使用get取数据库】
小程序通过云函数操作数据库【使用get取数据库】
2022-08-01 06:42:00 【元宇宙iwemeta】
云函数定义为getdatas,以下是云函数里面的index.js ,注意,此时的云函数入口函数里并不需要写回调函数,因为其得到的结果是直接返回即可了
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
return await db.collection("user_info").get();
}这里已经在云数据库里面有一个名为“user_info”的集合,如下:

在page_02的js里面添加以下的函数
cloudData:function(){
wx.cloud.callFunction({
name:"getdatas"
}).then(res=>{
console.log(res)
}).catch(err=>{
console.error(err)
})
}page_02的wxml如下
<view class="btn-area">
<button bindtap='cloudData'>Cloud</button>
</view>结果如下:

边栏推荐
猜你喜欢
随机推荐
Causes and solutions of lock table
Jupyter shortcuts
Datagrip error "The specified database userpassword combination is rejected..."Solutions
Seleniu: Common operations on elements
字符中的第一个唯一字符
将CSV文件快速导入MySQL中
爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
WebSocket implements chat function
MVVM project development (commodity management system 1)
轻量级的VsCode为何越用越大?为什么吃了我C盘10G?如何无痛清理VsCode缓存?手把手教你为C盘瘦身
torch
matplotlib pyplot
MATLAB程序设计与应用 2.5 MATLAB运算
return; represents meaning
数据湖:数据同步工具NiFi
Robot growth in China
【视觉SLAM十四讲】第一章理论详解
crypto-js uses
爬虫框架 Scrapy 详解
Using FiddlerScript caught poly FiddlerScript 】 【 download









