mpopulate

1.1.0 • Public • Published

mpopuate

Minimalistic population for node-mongodb-native

Build Status Coverage Status

var mc = require('mongodb').MongoClient
var mpopulate = require('mpopulate')

mc.connect('mongodb://localhost:27017/mpopulate').then(function (db) {
  return db.collection('posts').find().toArray()
  .then(function (posts) {
    console.log(posts)
    // [{
    //   _id: 1,
    //   title: 'title',
    //   author: 1
    // }]
    return mpopulate(posts)({
      author: function (ids) {
        return db.collection('users').find({
          _id: {
            $in: ids
          }
        })
        .toArray()
      }
    })
  })
  .then(function (posts) {
    console.log(posts)
    // [{
    //   _id: 1,
    //   title: 'title',
    //   author: {
    //     _id: 1
    //     name: 'name'
    //   }
    // }]
  })
})

Package Sidebar

Install

npm i mpopulate

Weekly Downloads

3

Version

1.1.0

License

MIT

Last publish

Collaborators

  • avoronkin