Comparing version 3.1.2 to 3.1.3
@@ -70,4 +70,7 @@ 'use strict'; | ||
_collections = {}; | ||
_safeOptions = extractOption('safe', options); | ||
_safeOptions = extractOption('safe', options, true); | ||
// enable safe by default | ||
_options.db = {safe: _safeOptions}; | ||
if (callback !== undefined) { | ||
@@ -74,0 +77,0 @@ mongodb.connect(_url, _options, function (err, db) { |
@@ -448,31 +448,9 @@ /** | ||
BaseModel[methodName] = function (id, fields, options, callback) { | ||
var hasFields = true; | ||
var isUnique = false; | ||
if (callback === undefined) { | ||
if (options === undefined) { | ||
callback = fields; | ||
options = {}; | ||
fields = {}; | ||
hasFields = false; | ||
} else { | ||
callback = options; | ||
options = fields; | ||
fields = {}; | ||
hasFields = false; | ||
} | ||
} | ||
if (options.unique !== undefined && options.unique === true) { | ||
isUnique = true; | ||
} | ||
if (!mongoCollection) { | ||
return callback('Cannot ' + methodName + ' on embedded model'); | ||
} | ||
var pluck = extractOption('pluck', options); | ||
if (pluck !== undefined) { | ||
// state that we only care about the plucked field | ||
fields[pluck] = true; | ||
hasFields = true; | ||
} | ||
BaseModel[methodName] = function (id, fields, options, callback) { | ||
if (id === undefined) { | ||
@@ -482,35 +460,10 @@ return callback('undefined id'); | ||
var includeNotFound = true; | ||
if (options.unique !== undefined && options.unique === true) { | ||
includeNotFound = false; | ||
} | ||
var query = {}; | ||
query[field] = id; | ||
return odm.findOne(mongoCollection, query, fields, options, function (err, documentLoaded) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
// if we search for an Id and get null it should return right away | ||
if (documentLoaded === null) { | ||
if (includeNotFound) { | ||
return callback(null, null); | ||
} else { | ||
return callback(mongoCollection + ' ' + id + ' not found'); | ||
} | ||
} | ||
if (hasFields) { | ||
if (pluck !== undefined) { | ||
documentLoaded = documentLoaded[pluck]; | ||
} | ||
return callback(null, documentLoaded); | ||
} | ||
documentLoaded[PROTO] = BaseModel.prototype; | ||
return callback(null, documentLoaded); | ||
}); | ||
if (isUnique) { | ||
return BaseModel.findOne(query, fields, options, callback); | ||
} else { | ||
return BaseModel.find(query, fields, options, callback); | ||
} | ||
}; | ||
@@ -562,2 +515,3 @@ } | ||
* @memberOf BaseModel.prototype | ||
* @param {Object} [partUpdate] partial update | ||
* @param {Object} [options] options for the query | ||
@@ -719,2 +673,3 @@ * @param {Function} callback Callback function (error, documentId) with the result of the operation | ||
* @memberOf BaseModel | ||
* @param {Object} document document to save | ||
* @param {Object|Function} [options] options for the query | ||
@@ -737,2 +692,3 @@ * @param {Function} callback Callback function (error, documentId) with the result of the operation | ||
* @memberOf BaseModel | ||
* @param {Object} document document to insert | ||
* @param {Object} [options] options for the query | ||
@@ -756,2 +712,3 @@ * @param {Function} callback Callback function (error, documentId) with the result of the operation | ||
* @param {Object} query Search query of objects to remove | ||
* @param {Object} document document to update the existing one | ||
* @param {Object} [options] options for the query | ||
@@ -758,0 +715,0 @@ * @param {Function} callback Callback function (error) with the result of the operation |
@@ -551,27 +551,9 @@ /** | ||
SchemaModel[methodName] = function (id, fields, options, callback) { | ||
var hasFields = true; | ||
var isUnique = false; | ||
if (callback === undefined) { | ||
if (options === undefined) { | ||
callback = fields; | ||
options = {}; | ||
fields = {}; | ||
hasFields = false; | ||
} else { | ||
callback = options; | ||
options = fields; | ||
fields = {}; | ||
hasFields = false; | ||
} | ||
} | ||
if (options.unique !== undefined && options.unique === true) { | ||
isUnique = true; | ||
} | ||
var pluck = extractOption('pluck', options); | ||
if (pluck !== undefined) { | ||
// state that we only care about the plucked field | ||
fields[pluck] = true; | ||
hasFields = true; | ||
} | ||
SchemaModel[methodName] = function (id, fields, options, callback) { | ||
if (id === undefined) { | ||
@@ -581,37 +563,10 @@ return callback('undefined id'); | ||
var includeNotFound = true; | ||
if (options.unique !== undefined && options.unique === true) { | ||
includeNotFound = false; | ||
} | ||
var query = {}; | ||
query[field] = id; | ||
return odm.findOne(mongoCollection, query, fields, options, function (err, documentLoaded) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
// clean up | ||
query = null; | ||
// if we search for an Id and get null it should return right away | ||
if (documentLoaded === null) { | ||
if (includeNotFound) { | ||
return callback(null, null); | ||
} else { | ||
return callback(mongoCollection + ' ' + id + ' not found'); | ||
} | ||
} | ||
if (hasFields) { | ||
if (pluck !== undefined) { | ||
documentLoaded = documentLoaded[pluck]; | ||
} | ||
} else { | ||
documentLoaded[PROTO] = SchemaModel.prototype; | ||
} | ||
return callback(null, documentLoaded); | ||
}); | ||
if (isUnique) { | ||
return SchemaModel.findOne(query, fields, options, callback); | ||
} else { | ||
return SchemaModel.find(query, fields, options, callback); | ||
} | ||
}; | ||
@@ -668,2 +623,3 @@ } | ||
* @memberOf SchemaModel.prototype | ||
* @param {Object} [partUpdate] update statement | ||
* @param {Object} [options] options for the query | ||
@@ -670,0 +626,0 @@ * @param {Function} callback Callback function (error, documentId) with the result of the operation |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"engines": { | ||
@@ -14,4 +14,4 @@ "node": ">=0.4.12" | ||
"dependencies": { | ||
"mongodb": "1.1.7", | ||
"jsonschema": "0.1.2" | ||
"mongodb": "1.1.11", | ||
"jsonschema": "0.1.3" | ||
}, | ||
@@ -18,0 +18,0 @@ |
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
14
0
77266
2499
+ Addedbson@0.1.5(transitive)
+ Addedjsonschema@0.1.3(transitive)
+ Addedmongodb@1.1.11(transitive)
- Removedbson@0.1.3(transitive)
- Removedjsonschema@0.1.2(transitive)
- Removedmongodb@1.1.7(transitive)
Updatedjsonschema@0.1.3
Updatedmongodb@1.1.11