xpress-mongo
Advanced tools
Comparing version 0.0.15 to 0.0.16
{ | ||
"name": "xpress-mongo", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Light Weight ODM for mongoDb", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,3 +31,3 @@ const GenerateModel = require('./XMongoModel'); | ||
if (typeof successCallback === 'function') | ||
successCallback(this); | ||
return successCallback(this); | ||
@@ -68,3 +68,3 @@ }).catch((err) => { | ||
/** | ||
* | ||
* Creates a model using current connection | ||
* @param collection | ||
@@ -71,0 +71,0 @@ * @return {typeof XMongoModel} |
@@ -392,2 +392,49 @@ const XMongoUsing = require('./XMongoUsing'); | ||
/** | ||
* Unset a key or keys from this collection | ||
* @param {string|[]} keys - Key or Keys to unset from collection | ||
* @param {Object} options - Update options | ||
*/ | ||
XMongoModel.prototype.unset = function (keys, options = {}) { | ||
// Throw Error if keys is undefined | ||
if (!keys) | ||
throw Error('Unset key or keys is required.'); | ||
// Throw Error if keys is not a string or array | ||
if (typeof keys !== "string" && typeof keys !== "object") | ||
throw Error('Unset key or keys must be typeof (String|Array)'); | ||
// Setup $unset object | ||
const $unset = {}; | ||
// Change keys to Array if its a string | ||
if (typeof keys === "string") keys = [keys]; | ||
// Loop Through and add to $unset object | ||
for (const key of keys) { | ||
$unset[key] = 1 | ||
} | ||
// Run MongoDb query and return response in Promise | ||
return new Promise((resolve, reject) => { | ||
return collection.updateOne( | ||
{_id: this.id()}, | ||
{$unset}, | ||
{}, | ||
(error, res) => { | ||
if (error) return reject(error); | ||
// Remove keys from current data | ||
for (const key of keys) { | ||
this.toCollection().unset(key); | ||
} | ||
return resolve(res) | ||
} | ||
) | ||
}); | ||
}; | ||
/** | ||
* Validate | ||
@@ -651,3 +698,3 @@ * @description | ||
XMongoModel.prototype.emptyData = function (replaceWith=undefined) { | ||
XMongoModel.prototype.emptyData = function (replaceWith = undefined) { | ||
this.data = { | ||
@@ -657,3 +704,3 @@ _id: this.id() | ||
if(replaceWith && typeof replaceWith === 'object') this.data = {...this.data, ...replaceWith}; | ||
if (replaceWith && typeof replaceWith === 'object') this.data = {...this.data, ...replaceWith}; | ||
@@ -660,0 +707,0 @@ return this; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46673
1396