cp-mongodb

封装项目中常用的mongodb数据库增删查改

Usage no npm install needed!

<script type="module">
  import cpMongodb from 'https://cdn.skypack.dev/cp-mongodb';
</script>

README

cp-mongodb

封装项目中常用到的文件上传发布,下载和存储

安装模块

cnpm i mongodb -S
cnpm i cp-mongodb -S

创建数据库连接

const mongodb = requier('cp-mongodb')
const mgConfig = {
  db: '' // 数据库
  user: '', // 数据库用户名
  pass: '' // 数据库密码
  host: '' // mongodb服务器
}
mongodb.createConnect(mgConfig)

新增数据

mongodb.add(res, table, params)

查询数据

// isList为true时为查询列表,false时为查询详情
mongodb.query(res, table, params, isList)

删除数据

// 通过自带的_id删除,可以传入字符串和数组
mongodb.del(res, table, params)

更新数据

// 通过数据的_id作为唯一标识更新
mongodb.update(res, table, params)