node.js - Reference one document from another (SQL-style join) with NeDB -
i have bunch of documents in nedb, let's of form:
{ _id : "3hdl4vdjqhcwvm76", type : "customer", name : "bob" }, { _id : "65bynnj7578b9hyu", type : "action", customer : "3hdl4vdjqhcwvm76", ... },
(so 'action' references 'customer')
and want list actions along customer names. obvious way be:
db.find({ type: 'action' }, function (err, actions) { actions.foreach(function(action) { db.findone({ type: 'customer', _id : action.customer }, function (err, customer) { console.log(action, customer.name); }); }); });
but gets painful quite quickly. there better way of doing this? like:
db.find({ type: 'action' }, {join : ["customer"]}, function (err, actions) { console.log(action, action.customer.name); });
would awesome.
it seems common thing want do, can't seem find information on doing it.
thanks!
Comments
Post a Comment