remove and insertOne operations
This commit is contained in:
parent
2744dfd22b
commit
be15e50d6a
@ -26,7 +26,8 @@ class MongoDBProvider extends Provider {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_query(query) {
|
_query(request) {
|
||||||
|
|
||||||
/* Query object structure
|
/* Query object structure
|
||||||
{
|
{
|
||||||
type: '', -- The function to use from this class, ex. findOne
|
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 (!this._initialized) return { error: true, message: 'MongoDB not connected' };
|
||||||
if(!query.collection) return { error: true, message: `You must specify a collection to query!` };
|
if (!this[request.type]) return { error: true, message: `Invalid request type, got '${request.type}'` };
|
||||||
return this[query.type](query);
|
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
|
* Find and return the first match
|
||||||
* @memberof Database
|
* @memberof Database
|
||||||
|
Loading…
Reference in New Issue
Block a user