Relevant packages:
"dependencies": {
"mongodb": "1.4.x",
"bluebird": "2.3.x"
}
I've looked at:
- How can I promisify the MongoDB native Javascript driver using bluebird?
- Bluebird Promisfy.each, with for-loops and if-statements?
- https://stackoverflow.com/a/21733446/438992
- Bluebird's promisification docs
- A few other places
I'm stuck after the findAsync({})
.
I'd prefer a cursor, but it's rare I'd have too much to call toArray()
.
It's also possible I'm doing this completely wrong.
MongoClient.connectAsync('mongodb://127.0.0.1:27017/sr')
.then(function(_db) {
db = _db;
return db.collectionAsync('posts');
})
.then(function(colPosts) {
return colPosts.findAsync({});
})
.then ( A MIRACLE OCCURS )
.catch(function(e) {
console.log(e);
})
.finally(function() {
if (db) db.close();
});
Where the miracle occurs I want to either iterate over the cursor results or the arrayified collection. I'm having problems figuring out how to go about this.