nswbmw / koa-mongo

MongoDB middleware for koa, support connection pool.
145 stars 31 forks source link

Examples of find and data manipulation #7

Closed jrschumacher closed 8 years ago

jrschumacher commented 9 years ago

Could you give an example of how the following would be done?

app.use(function* (next) {
  this.mongo.db('test').collection('users').find({}, function (err, docs) {
    docs.toArray(function(err, doc) {
      doc.name += '!';
    });
  });
});
Globik commented 8 years ago

You may now use generator function instead callback. Say, yield db.collection("users").find().toArray() ;etc...

Globik commented 8 years ago

Dont forget also yield next;