Permalink
Browse files

Support conditions to count(); don't wrap numeric callback values (mo…

…del.count was completely broken)
  • Loading branch information...
1 parent f8f81a6 commit 7d27764b6d04d6895be689ab49a00c6ad9e944bd @JoshuaGross committed Nov 6, 2012
Showing with 6 additions and 3 deletions.
  1. +5 −2 lib/mongoose-subpopulate.js
  2. +1 −1 package.json
View
7 lib/mongoose-subpopulate.js
@@ -95,7 +95,7 @@ var wrapSchema = exports.wrapSchema = function wrapSchema (schema) {
('function' === typeof conditions && (callback = conditions) && (conditions = undefined));
var wrapCallback = (callback ? db_callback('count failed', callback) : null);
try {
- return wrapSchema(countOrig.call(schema, wrapCallback));
+ return wrapSchema(countOrig.call(schema, conditions, wrapCallback));
} catch (mongooseError) {
wrapCallback(mongooseError);
}
@@ -296,7 +296,7 @@ function wrapModelObject (object, cacheData, callback) {
}
cacheData = cacheData || {};
- if (object === null || object === undefined || object.mongooseLink) {
+ if (object === null || object === undefined || 'number' === typeof object || object.mongooseLink) {
return (callback ? callback(object, cacheData) : object);
}
@@ -484,6 +484,9 @@ exports.extendMongoose = function (mongooseIn, defineModels) {
if (str && (str.toString()).match(/^[a-zA-Z0-9]+$/) && str.length === 24) return str;
return null;
};
+ mongoose.toObjectID = function (obj) {
+ return new mongoose.Types.ObjectId(mongoose.toID(obj));
+ };
mongoose.objectsEqual = function (obj1, obj2) {
return mongoose.toID(obj1) === mongoose.toID(obj2);
};
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "mongoose-subpopulate",
- "version": "0.1.11",
+ "version": "0.1.12",
"main": "./lib/mongoose-subpopulate.js",
"scripts": {},
"repository": {

0 comments on commit 7d27764

Please sign in to comment.