unicloud表增删改查

摘要:
“usestrict”;constdb=uniCloud。数据库();出口。main=async(event,context)=˃{//event是客户端上载的参数console.log(event.a)//constructions=[]if(event.a==1){//添加console.log(111)constcollection=db.collection('uni-id使用

'use strict';
const db=uniCloud.database();
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log(event.a)
//const res=[]
if(event.a==1){
//增
console.log(111)
const collection=db.collection('uni-id-users');
var res=await collection.add([
{
"_id_":2,
"username":"胖虎",
"mobile":"18253590666",
"gong":1
}
])
}
if(event.a == "2" ){
console.log(222)
//查


const collection=db.collection('uni-id-users');
//限制条数
// var res=await collection.limit(2).get()
var res=await collection.get()
/*var res=await collection.where({

gong:1
}).get()*/
//单条
// var res=await collection.doc('60ab465c3b7d3500014a294d').get()

//根据条件,倒叙,分页

var res=await collection.where({
xh: event.xh
}).orderBy("time", "desc").skip((event.page) * 20).limit(20).get()


}
if(event.a == "3" ){
//改
const collection=db.collection('uni-id-users');

//如果当前_id的记录不存在,那么不会更新任何数据
/*var res=await collection.doc('60ab465c3b7d3500014a294d').update({
username:'老胖虎'
})*/
//如果当前_id的记录不存在,会增加一跳数据
var res=await collection.doc('60ab465c3b7d3500014a294d').set({
username:'老胖虎'
})
}
if(event.a == "4" ){
console.log(222)
//删除


const collection=db.collection('uni-id-users');

var res=await collection.where({

_id:'60ab465c3b7d3500014a294d'
}).remove()
}
//返回数据给客户端
return {
code:200,
data:res,
msg:'OK'
}
};

免责声明:文章转载自《unicloud表增删改查》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【转】C#中PrintDocument类详解kill命令下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

03点云文件常用格式转换(pcd,txt,ply,obj,stl)

1.pcd到txt1#include<iostream>2#include<fstream>3#include<pcl/io/pcd-io。h˃ 45intmain(intargc,char*argv[])6{78pcl::PointCloud<pcl:点XYZ>::Ptrcloud...

内存数据库-H2简介与实践

该模式下,H2数据库可以部署在不同的JVM或不同的物理机中,多个应用可以通过连接H2服务器同时连接到H2数据库。混合模式示意图如下:1.3H2数据库JDBCURL格式H2数据库支持多种连接方式和连接设置,连接URL格式如下,URL中的设置大小写不敏感。...

Ubuntu安装时怎样分区

应该首先放置启动分区。并将引导设置为主分区。如果是双系统或多系统安装,通常可以选择逻辑分区。首先,Grub可以在1024柱面后面引导Linux内核;第二,即使有多个Linux安装,/boot也可以完全不共享。此外,非独立/引导分区仅占用根文件夹下约20MB的空间。所以决定是否启动。...

js学习-es6实现枚举

最近,我大部分时间都在写dart,突然使用了js。我发现js不能直接声明枚举。目录枚举功能对象冻结()符号实现反映了不可更改值的唯一性。请注意,枚举特性枚举值不能重复,也不能修改。Switchcase可以直接判断对象。冻结()对象。方法可以冻结对象。无法更改实现constEnumSex=Object。冷冻枚举性别。人=1;安慰日志;//符号(男性)表示值co...

如何让 ESLint 同时检测 js 和 ts

但是ESLint默认使用Espree作为其解析器,在某些情况下不支持TypeScript语法。另外,TypeScript是JavaScript超集,有更多的语法,ESLint本身提供的规则无法满足。ESLint有一项overrides的配置,可以为某个文件或者某组文件进行覆盖配置。因此,我们可以设置ts文件使用@typescript-eslint/parse...

C#中将字符串转成 Base64 编码(小技巧)

///////////////publicstringToBase64Str(stringStr){byte[]b=System.Text.Encoding.Default.GetBytes(Str);returnConvert.ToBase64String(b);}///...