backbone-db-mongodb
Advanced tools
Comparing version 0.2.9 to 0.2.10
23
index.js
@@ -91,9 +91,9 @@ var _ = require('lodash'), | ||
} | ||
options.where = searchAttrs; | ||
} | ||
var self = this; | ||
var query = options.where || {}; | ||
var offset = options.offset || 0; | ||
var limit = options.limit || this.limit || 50; | ||
var self = this; | ||
var sort = options.sort ? convertSort(options.sort) : { | ||
@@ -119,7 +119,14 @@ $natural: 1 | ||
.limit(limit) | ||
.toArray(function (err, res) { | ||
if(err || !res) return callback(err, res); | ||
res = self._filter(res, model); | ||
if(!model.model) return callback(err, res && res.length && res[0]); | ||
callback(err, res); | ||
.toArray(function (err, results) { | ||
if(!model.model) { | ||
if(!results || results.length === 0) { | ||
err = err || new Error('not found'); | ||
} else { | ||
results = self._filter(results, model); | ||
} | ||
return callback(err, results && results.length && results[0]); | ||
} | ||
if(err || !results) return callback(err, results); | ||
results = self._filter(results, model); | ||
callback(null, results); | ||
}); | ||
@@ -243,2 +250,2 @@ }); | ||
module.exports = Db.MongoDB = MongoDB; | ||
module.exports = Db.MongoDB = MongoDB; |
{ | ||
"name": "backbone-db-mongodb", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"description": "MongoDB driver for Backbone.Db", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
122970
787