当前位置:网站首页>小程序通过云函数操作数据库【使用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>
结果如下:
边栏推荐
- Seleniu: Common operations on elements
- 声音信号处理基频检测和时频分析
- WebSocket实现聊天功能
- matplotlib pyplot
- Data organization -- singly linked list of the linear table
- The BP neural network based on MATLAB voice characteristic signal classification
- 2022.7.26 Mock Competition
- 戴尔PowerEdge服务器R450 RAID配置步骤
- 上课作业(7)——#598. 取余运算(mod)
- 【视觉SLAM十四讲】第一章理论详解
猜你喜欢
随机推荐
JS的运行原理
湖仓一体电商项目(一):项目背景和架构介绍
Qt Widget 项目对qml的加载实例
Speed up your programs with bitwise operations
爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
Selenium: Dropdown Box Actions
Practical training Navicat Chinese and English mode switching
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
AspNet.WebApi.Owin 自定义Token请求参数
AspNet.WebApi.Owin custom Token request parameters
我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer
MVVM项目开发(商品管理系统一)
05-SDRAM: Arbitration
小白的0基础教程SQL: 安装MYSQL 03
Causes and solutions of lock table
目标检测概述-上篇
Jupyter shortcuts
2022年牛客多校第四场补题
dbeaver连接MySQL数据库及错误Connection refusedconnect处理
Data organization -- singly linked list of the linear table