Comparing version 0.0.13 to 0.0.14
123
lib/model.js
@@ -52,3 +52,3 @@ 'use strict'; | ||
if (typeof(dbdata) === 'object') { | ||
if (typeof dbdata === 'object') { | ||
for (key in dbdata) { | ||
@@ -146,3 +146,3 @@ if (dbdata.hasOwnProperty(key)) { | ||
function matchValue(search, value, reverse) { | ||
var hasEquals = search.equals !== undefined && search.equals !== null && typeof(search.equals) === 'function'; | ||
var hasEquals = search.equals !== undefined && search.equals !== null && typeof search.equals === 'function'; | ||
@@ -233,3 +233,3 @@ if (hasEquals) { | ||
for (j = 0; j < search.length; j++) { | ||
if (matchValue(search[j], obj[key], negate)) { | ||
if (matchValue(search[j], obj[key], false)) { | ||
matched = true; | ||
@@ -239,4 +239,10 @@ break; | ||
} | ||
if (!matched) { | ||
return 0; | ||
if (negate) { | ||
if (matched) { | ||
return 0; | ||
} | ||
} else { | ||
if (!matched) { | ||
return 0; | ||
} | ||
} | ||
@@ -348,3 +354,3 @@ } else { | ||
} else { | ||
if (typeof(id) === 'string' && id.length === 24 && objectIdRegExp.test(id)) { | ||
if (typeof id === 'string' && id.length === 24 && objectIdRegExp.test(id)) { | ||
_id = ObjectID.createFromHexString(id); | ||
@@ -516,3 +522,3 @@ } else { | ||
var hasEquals = val.equals !== undefined && val.equals !== null && typeof(val.equals) === 'function'; | ||
var hasEquals = val.equals !== undefined && val.equals !== null && typeof val.equals === 'function'; | ||
@@ -548,3 +554,3 @@ for (i = 0; i < value.length; i++) { | ||
var hasEquals = val.equals !== undefined && val.equals !== null && typeof(val.equals) === 'function'; | ||
var hasEquals = val.equals !== undefined && val.equals !== null && typeof val.equals === 'function'; | ||
@@ -579,3 +585,3 @@ for (i = 0; i < value.length; i++) { | ||
var hasEquals = val.equals !== undefined && val.equals !== null && typeof(val.equals) === 'function'; | ||
var hasEquals = val.equals !== undefined && val.equals !== null && typeof val.equals === 'function'; | ||
@@ -1045,2 +1051,24 @@ for (i = 0; i < value.length; i++) { | ||
// verify if it is in cache | ||
if (l2cache) { | ||
var _id = JSON.stringify(query); | ||
var cachedDocument = cache.get(_id); | ||
if (cachedDocument !== undefined) { | ||
// if we search for an Id and get null return right away | ||
if (cachedDocument === null) { | ||
return callback(null, null); | ||
} | ||
// special case (return direct document from mongoDB) | ||
if (directObject) { | ||
return callback(null, cachedDocument); | ||
} | ||
var model = new Model(cachedDocument, { deserialize: true }); | ||
return callback(null, model); | ||
} | ||
} | ||
odm.collection(mongoCollection, options, function (err, collection) { | ||
@@ -1100,3 +1128,3 @@ if (err) { | ||
} else { | ||
if (typeof(id) === 'string' && id.length === 24 && objectIdRegExp.test(id)) { | ||
if (typeof id === 'string' && id.length === 24 && objectIdRegExp.test(id)) { | ||
_id = ObjectID.createFromHexString(id); | ||
@@ -1201,2 +1229,10 @@ } else { | ||
var pluck = extractOption('pluck', options); | ||
if (pluck !== undefined) { | ||
directObject = true; | ||
// state that we only care about the plucked field | ||
fields[pluck] = true; | ||
} | ||
collection.find(query, fields, options, function (err, cursor) { | ||
@@ -1210,8 +1246,16 @@ if (err) { | ||
} | ||
var i; | ||
// special case (return direct document from mongoDB) | ||
if (directObject) { | ||
return callback(null, documentsLoaded); | ||
if (pluck !== undefined) { | ||
for (i = 0; i < documentsLoaded.length; i++) { | ||
documentsLoaded[i] = documentsLoaded[i][pluck]; | ||
} | ||
return callback(null, documentsLoaded); | ||
} else { | ||
return callback(null, documentsLoaded); | ||
} | ||
} | ||
var i; | ||
for (i = 0; i < documentsLoaded.length; i++) { | ||
@@ -1253,2 +1297,10 @@ documentsLoaded[i] = new Model(documentsLoaded[i], { deserialize: true }); | ||
var pluck = extractOption('pluck', options); | ||
if (pluck !== undefined) { | ||
directObject = true; | ||
// state that we only care about the plucked field | ||
fields[pluck] = true; | ||
} | ||
// verify if it is in cache | ||
@@ -1260,9 +1312,17 @@ if (l2cache) { | ||
var documentsLoaded = []; | ||
var i; | ||
// special case (return direct document from mongoDB) | ||
if (directObject) { | ||
return callback(null, cachedDocuments); | ||
if (pluck !== undefined) { | ||
for (i = 0; i < cachedDocuments.length; i++) { | ||
documentsLoaded[i] = cachedDocuments[i][pluck]; | ||
} | ||
return callback(null, documentsLoaded); | ||
} else { | ||
return callback(null, cachedDocuments); | ||
} | ||
} | ||
var documentsLoaded = []; | ||
var i; | ||
for (i = 0; i < cachedDocuments.length; i++) { | ||
@@ -1289,3 +1349,3 @@ documentsLoaded[i] = new Model(cachedDocuments[i], { deserialize: true }); | ||
if (l2cache) { | ||
if (l2cache && pluck === undefined) { | ||
cache.set('all', documentsLoaded); | ||
@@ -1296,3 +1356,10 @@ } | ||
if (directObject) { | ||
return callback(null, documentsLoaded); | ||
if (pluck !== undefined) { | ||
for (i = 0; i < documentsLoaded.length; i++) { | ||
documentsLoaded[i] = documentsLoaded[i][pluck]; | ||
} | ||
return callback(null, documentsLoaded); | ||
} else { | ||
return callback(null, documentsLoaded); | ||
} | ||
} | ||
@@ -1346,16 +1413,26 @@ | ||
var i; | ||
var _ids = ids; | ||
for (i = 0; i < ids.length; i++) { | ||
if (! ids[i] instanceof ObjectID) { | ||
var pluck = extractOption('pluck', options); | ||
if (pluck !== undefined) { | ||
_ids = []; | ||
for (i = 0; i < ids.length; i++) { | ||
_ids[i] = ids[i][pluck]; | ||
} | ||
} | ||
for (i = 0; i < _ids.length; i++) { | ||
if (!(_ids[i] instanceof ObjectID)) { | ||
return callback('Non ObjectId in the array'); | ||
} | ||
if (index[ids[i].toHexString()] === undefined) { | ||
index[ids[i].toHexString()] = [i]; | ||
if (index[_ids[i].toHexString()] === undefined) { | ||
index[_ids[i].toHexString()] = [i]; | ||
} else { | ||
index[ids[i].toHexString()].push(i); | ||
index[_ids[i].toHexString()].push(i); | ||
} | ||
} | ||
this.find({_id: {'$in': ids}}, fields, options, function (err, models) { | ||
this.find({_id: {'$in': _ids}}, fields, options, function (err, models) { | ||
if (err) { | ||
@@ -1362,0 +1439,0 @@ return callback(err); |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"engines": { | ||
@@ -11,0 +11,0 @@ "node": ">=0.4.12" |
Sorry, the diff of this file is not supported yet
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
88530
1848