forked from Galactic/galactic-bot
load checks
This commit is contained in:
parent
aae82e2ed5
commit
4a403c2d6d
@ -44,11 +44,11 @@ class MongoDBProvider extends Provider {
|
||||
|
||||
find(db, query) {
|
||||
|
||||
if(!this.loaded) throw new Error('MongoDB not connected');
|
||||
|
||||
//if(this.manager.debug) this.manager.logger.debug(`Incoming find query for ${db} with parameters ${JSON.stringify(query)}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(!this.loaded) reject(new Error('MongoDB not connected'));
|
||||
|
||||
this.db.collection(db).find(query, async (error, cursor) => {
|
||||
|
||||
if(error) return reject(error);
|
||||
@ -71,11 +71,11 @@ class MongoDBProvider extends Provider {
|
||||
|
||||
findOne(db, query) {
|
||||
|
||||
if(!this.loaded) throw new Error('MongoDB not connected');
|
||||
|
||||
//if(this.manager.debug) this.manager.logger.debug(`Incoming findOne query for ${db} with parameters ${JSON.stringify(query)}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(!this.loaded) reject(new Error('MongoDB not connected'));
|
||||
|
||||
this.db.collection(db).findOne(query, async (error, item) => {
|
||||
|
||||
if(error) return reject(error);
|
||||
@ -99,10 +99,10 @@ class MongoDBProvider extends Provider {
|
||||
*/
|
||||
updateOne(db, query, data, upsert = false) {
|
||||
|
||||
if(!this.loaded) throw new Error('MongoDB not connected');
|
||||
|
||||
//if(this.manager.debug) this.manager.logger.debug(`Incoming updateOne query for ${db} with parameters ${JSON.stringify(filter)}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(!this.loaded) reject(new Error('MongoDB not connected'));
|
||||
|
||||
this.db.collection(db).updateOne(query, { $set: data }, { upsert: upsert }, async (error, result) => {
|
||||
|
||||
@ -130,11 +130,11 @@ class MongoDBProvider extends Provider {
|
||||
*/
|
||||
push(db, query, data, upsert = false) {
|
||||
|
||||
if(!this.loaded) throw new Error('MongoDB not connected');
|
||||
|
||||
//if(this.manager.debug) this.manager.logger.debug(`Incoming push query for ${db}, with upsert ${upsert} and with parameters ${JSON.stringify(filter)} and data ${JSON.stringify(data)}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(!this.loaded) reject(new Error('MongoDB not connected'));
|
||||
|
||||
this.db.collection(db).updateOne(query, { $push: data }, { upsert: upsert }, async (error, result) => {
|
||||
|
||||
if(error) return reject(error);
|
||||
@ -157,13 +157,13 @@ class MongoDBProvider extends Provider {
|
||||
*/
|
||||
random(db, query = {}, amount = 1) {
|
||||
|
||||
if(!this.loaded) throw new Error('MongoDB not connected');
|
||||
|
||||
//if(this.manager.debug) this.manager.logger.debug(`Incoming random query for ${db} with parameters ${JSON.stringify(filter)} and amount ${amount}`);
|
||||
if(amount > 100) amount = 100;
|
||||
|
||||
return new Promise((resolve, reject)=>{
|
||||
|
||||
if(!this.loaded) reject(new Error('MongoDB not connected'));
|
||||
|
||||
this.db.collection(db).aggregate([{ $match: query }, { $sample: {size: amount}}], function(err, item) {
|
||||
|
||||
if(err) return reject(err);
|
||||
|
Loading…
Reference in New Issue
Block a user