Skip to content

Commit

Permalink
collection: make findAndModify accept _id as the target
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Sep 6, 2012
1 parent 8be2758 commit e2cf3b8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var util = require('./util')
, debug = require('debug')('monk:queries')
, EventEmitter = require('events').EventEmitter
, Promise = require('./promise')
, Promise = require('./promise');

/**
* Module exports
Expand Down Expand Up @@ -89,7 +89,7 @@ Collection.prototype.ensureIndex = function (fields, opts, fn) {

var fields = util.fields(fields)
, opts = opts || {}
, promise = new Promise(this, 'index')
, promise = new Promise(this, 'index');

if (fn) {
promise.complete(fn);
Expand Down Expand Up @@ -246,6 +246,10 @@ Collection.prototype.findAndModify = function (query, update, opts, fn) {
fn = opts;
}

if ('string' == typeof query.query || 'function' == typeof query.query.toHexString) {
query.query = { _id: query.query };
}

if ('function' == typeof opts) {
fn = opts;
opts = {};
Expand Down Expand Up @@ -345,7 +349,7 @@ Collection.prototype.find = function (query, opts, fn) {
opts = {};
}

var promise = new Promise(this, 'find')
var promise = new Promise(this, 'find');

if (fn) {
promise.complete(fn);
Expand Down Expand Up @@ -400,7 +404,7 @@ Collection.prototype.find = function (query, opts, fn) {
*/

Collection.prototype.count = function (query, fn) {
var promise = new Promise(this, 'find')
var promise = new Promise(this, 'find');

if (fn) {
promise.complete(fn);
Expand Down

0 comments on commit e2cf3b8

Please sign in to comment.