Reputation: 40522
var co = require('co');
var MongoClient = require('mongoskin').MongoClient;
var db = MongoClient.connect('mongodb://localhost:27017/hellye');
var countries = db.collection('countries', {
strict: true
});
co(function* () {
var doc =
yield countries.find({
country: 'scotland'
}).limit(1);
console.log('> 1');
console.log(doc);
});
countries.find({
country: 'scotland'
}).limit(1).next(function (err, doc) {
console.log('> 2');
console.log(doc);
});
The code above outputs the following in the console:
> 2
{ _id: 56b33957a345a53d4c15f6bf,
country: 'scotland',
primaryLanguage: 'english' }
The first query does not work, why is this? Documentation says it returns a Promise so it should: https://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#find
Upvotes: 0
Views: 54
Reputation: 40522
.toArray()
was needed on the end.
var doc =
yield countries.find({
country: 'scotland'
}).limit(1).toArray();
Upvotes: 0