Comparing version 3.1.14 to 3.1.15
@@ -268,7 +268,55 @@ 'use strict'; | ||
* @memberOf ODM | ||
* | ||
* @param {String} collection_name | ||
* @param {Object} query | ||
* @param {Object} sort | ||
* @param {Object} document | ||
* @param {Object} options | ||
* @param {Function} callback | ||
*/ | ||
findAndModify: function (collection_name, query, sort, document, options, callback) { | ||
var wantCursor = extractOption('cursor', options, false); | ||
ODM.collection(collection_name, options, function (err, collection) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return collection.findAndModify(query, sort, document, options, function (err, cursor) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (wantCursor) { | ||
if (cursor.state !== Cursor.CLOSED) { | ||
return callback(null, cursor); | ||
} | ||
return callback('Cursor is closed'); | ||
} | ||
return cursor.toArray(function (err, array) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
// clean resources | ||
if (!cursor.isClosed()) { | ||
cursor.close(); | ||
} | ||
return callback(null, array); | ||
}); | ||
}); | ||
}); | ||
}, | ||
/** | ||
* @static | ||
* @memberOf ODM | ||
* @param {String} collection_name | ||
* @param {Object} query | ||
* @param {Object} options | ||
* @param {Function} callback | ||
*/ | ||
count: function (collection_name, query, options, callback) { | ||
@@ -275,0 +323,0 @@ ODM.collection(collection_name, options, function (err, collection) { |
@@ -293,2 +293,22 @@ /** | ||
/** | ||
* Updates a set of documents and returns the updates docs. | ||
* | ||
* @static | ||
* @memberOf Model | ||
* @param {Object} query MongoDB Query | ||
* @param {Object} sort sorting order | ||
* @param {Object} document update | ||
* @param {Object} [options] options for the query | ||
* @param {Function} callback Callback function (error, model) with the result of the operation | ||
*/ | ||
Model.findAndModify = function (query, sort, document, options, callback) { | ||
if (callback === undefined) { | ||
callback = options; | ||
options = {}; | ||
} | ||
return odm.findAndModify(mongoCollection, query, sort, document, options, callback); | ||
}; | ||
/** | ||
* Finds all elements in this collection. | ||
@@ -655,2 +675,20 @@ * | ||
/** | ||
* Updates a set of documents and returns the updates docs. | ||
* | ||
* @static | ||
* @memberOf Model | ||
* @param {Object} document update | ||
* @param {Object} [options] options for the query | ||
* @param {Function} callback Callback function (error, model) with the result of the operation | ||
*/ | ||
Model.prototype.findAndModify = function (document, options, callback) { | ||
if (callback === undefined) { | ||
callback = options; | ||
options = {}; | ||
} | ||
return odm.findAndModify(mongoCollection, {_id: self._id}, {_id: 'asc'}, document, options, callback); | ||
}; | ||
/** | ||
* Creates a snapshot of this object instance. | ||
@@ -657,0 +695,0 @@ * |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "3.1.14", | ||
"version": "3.1.15", | ||
"engines": { | ||
@@ -14,3 +14,3 @@ "node": ">=0.4.12" | ||
"dependencies": { | ||
"mongodb": "1.2.5", | ||
"mongodb": "1.2.12", | ||
"jsonschema": "0.3.2" | ||
@@ -17,0 +17,0 @@ }, |
95948
3142
+ Addedbson@0.1.7(transitive)
+ Addedmongodb@1.2.12(transitive)
- Removedbson@0.1.5(transitive)
- Removedmongodb@1.2.5(transitive)
Updatedmongodb@1.2.12