1.0.1 • Published 1 year ago

mongo_atlas_dataapi v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

mongo_atlas_dataapi

是对 mongodb Atlas Data API 接口的封装 官方文档

set_api_key

import mada from 'mongo_atlas_dataapi'
mada.set_api_key("Your data api key")

接口统一格式

/**
 * @example findOne
 * @param {{}} data - 请求数据,不同接口数据不同,参考文档
 * @param {string} collection - 要操作的集合
 * @param {string} [database=project] - 要操作的数据库, 默认值为project
 */
findOne(data, collection, database)

findOne

var res = await findOne({
    filter: { type: 'your-filter' }
}, 'your-collection')

var json = await res.json()
var data = json.document

find

var res = await find({
    filter: { type: 'your-filter' }
}, 'your-collection')

var json = await res.json()
var data = json.document

updateOne

// update
var updateRes = await updateOne({
    upsert: true,
    filter: {
        type: 'your-filter' 
    },
    update: {
        $inc: {
            count: 1
        }
    },
}, 'your collection', 'project')

json = await updateRes.json()
console.log('update result', json)
1.0.1

1 year ago

1.0.0

1 year ago