remove and insertOne operations

This commit is contained in:
Erik 2020-04-17 23:18:08 +03:00
parent 2744dfd22b
commit be15e50d6a

View File

@ -26,7 +26,8 @@ class MongoDBProvider extends Provider {
}
_query(query) {
_query(request) {
/* Query object structure
{
type: '', -- The function to use from this class, ex. findOne
@ -36,13 +37,44 @@ class MongoDBProvider extends Provider {
}
*/
if(!this[query.type]) return { error: true, message: `Invalid query type, got '${query.type}'` };
if(!query.collection) return { error: true, message: `You must specify a collection to query!` };
return this[query.type](query);
if (!this._initialized) return { error: true, message: 'MongoDB not connected' };
if (!this[request.type]) return { error: true, message: `Invalid request type, got '${request.type}'` };
if (!request.collection) return { error: true, message: `You must specify a collection to query!` };
return this[request.type](request);
}
remove({ collection, query }) {
return new Promise((resolve, reject) => {
this.db.collection(collection).remove(query, (err, result) => {
if (err) reject(err);
resolve(result);
});
});
}
insertOne({ collection, data }) {
return new Promise((resolve, reject) => {
this.db.collection(collection).insertOne(data, (err, result) => {
if(err) reject(err);
resolve(result);
});
});
}
/**
* Find and return the first match
* @memberof Database