Files
Sliverkiss-QuantumultX/Utils/MongoDB.min.js
2025-10-11 16:12:07 +08:00

2 lines
1.5 KiB
JavaScript

function MongoDB(t, n, o, e, s) { return new class { constructor(t, n, o, e, s) { this.BASE_URL = t, this.username = n, this.password = o, this.database = e, this.collection = s } async commonPost(t) { const { url: n, headers: o, body: e, method: s = "post" } = t, a = { url: `${this.BASE_URL}${n}`, headers: { "Content-Type": "application/json", Accept: "application/json", ...o }, body: $.toStr({ USERNAME: this.username, PASSWORD: this.password, DATABASE: this.database, COLLECTION: this.collection, ...e }) }; return $.info($.toStr(a.body)), new Promise((t => { $[s](a, ((n, o, e) => { let s = $.toObj(e) || e; t(s) })) })) } async findOne(t) { const n = { url: "/findOne", body: { filter: t } }; return await this.commonPost(n) } async find(t) { const n = { url: "/find", body: { filter: t } }; return await this.commonPost(n) } async insertOne(t) { const n = { url: "/insertOne", body: { document: t } }; return await this.commonPost(n) } async insertMany(t) { const n = { url: "/insertMany", body: { documents: t } }; return await this.commonPost(n) } async updateOne(t, n) { const o = { url: "/updateOne", body: { filter: t, update: n } }; return await this.commonPost(o) } async updateMany(t, n) { const o = { url: "/updateMany", body: { filter: t, update: n } }; return await this.commonPost(o) } async deleteOne(t) { const n = { url: "/deleteOne", body: { filter: t } }; return await this.commonPost(n) } async deleteMany(t) { const n = { url: "/deleteMany", body: { filter: t } }; return await this.commonPost(n) } }(t, n, o, e, s) }