mongodb-promise
Advanced tools
Comparing version
@@ -224,22 +224,15 @@ var Q = require('q'); | ||
* Creates a cursor for a query that can be used to iterate over results from MongoDB | ||
* @param query | ||
* @param sort | ||
* @param options | ||
* @returns {promise|*|Q.promise} | ||
* @param {Object} query | ||
* @param {Array} sort | ||
* @param {Object} [options] | ||
* @returns {Cursor} | ||
*/ | ||
Collection.prototype.find = function(query, sort, options) { | ||
var deferred = Q.defer(); | ||
this._col.find(query, sort, options || {}, function(err, cursor) { | ||
if(err) { | ||
deferred.reject(err); | ||
} else { | ||
deferred.resolve(new Cursor(cursor)); | ||
} | ||
}); | ||
return deferred.promise; | ||
var _cursor = this._col.find(query, sort, options); | ||
return new Cursor(_cursor); | ||
}; | ||
/** | ||
* Creates an index on the collection. | ||
* @param fieldOrSpec | ||
* @param options | ||
* @param {Object} fieldOrSpec | ||
* @param {Object} [options] | ||
* @returns {promise|*|Q.promise} | ||
@@ -246,0 +239,0 @@ */ |
@@ -5,2 +5,3 @@ | ||
exports.MongoClient = require('./mongo-client').MongoClient; | ||
exports.Cursor = require('./cursor').Cursor; | ||
@@ -7,0 +8,0 @@ |
{ | ||
"name": "mongodb-promise", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A mongodb-native promise library", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -45,3 +45,3 @@ mongodb-promise | ||
// Read documents | ||
// Read all documents | ||
mp.MongoClient.connect("mongodb://127.0.0.1:27017/test") | ||
@@ -63,2 +63,17 @@ .then(function(db){ | ||
// Read each document | ||
mp.MongoClient.connect("mongodb://127.0.0.1:27017/test") | ||
.then(function(db){ | ||
return db.collection('test') | ||
.then(function(col) { | ||
return col.find({a : 1}).each(function(doc) { | ||
console.log(doc); | ||
}) | ||
.then(function() { | ||
db.close().then(console.log('success')); | ||
}) | ||
}) | ||
}) | ||
.fail(function(err) {console.log(err);}); | ||
``` | ||
@@ -65,0 +80,0 @@ ## Download |
25136
1.49%84
21.74%779
-0.76%