Able to find one specific document

pull/2/head
Louis Chatriot 12 years ago
parent 6aeaa80aff
commit ad2a0700dc
  1. 27
      lib/datastore.js

@ -130,15 +130,32 @@ Datastore.prototype.find = function (query, callback) {
};
/**
* Find one document matching the query
* @param {Object} query MongoDB-style query
*/
Datastore.prototype.findOne = function (query, callback) {
var self = this
, i
;
for (i = 0; i < self.data.length; i += 1) {
if (Datastore.match(self.data[i], query)) {
return callback(null, self.data[i]);
}
}
return callback(null, null);
};
var d = new Datastore('workspace/test.db');
d.loadDatabase(function (err) {
console.log(d.data);
d.find({ te: "un" }, function (err, docs) {
console.log(err);
console.log('------------------');
console.log(docs);
});
});

Loading…
Cancel
Save