node.js - Using and populating (real) DBRef arrays with Mongoose / mongoose-dbref -


mongoose doesn't appear support mongo dbrefs. apparently released "dbref" support plain references (no ability reference documents different collections). i've managed craft schema allows me hold array of objectid references , populate them, great parts of schema, extremely convenient if use proper dbrefs create array lets me refer documents number of collections.

luckily(?) there's module can monkey patch dbref support mongoose: https://github.com/goulash1971/mongoose-dbref

unluckily, can't make sense of documents. best can tell there no ability use dbrefs in array (there 'fetch' method dereference, takes single dbref); 'populate' doesn't seem patched fill in dbrefs, , can't tell how i'm supposed assign dbref given source document [collection.items.push(?????)].

from internet, appears can assign object of form { $id: document._id, $ref: 'collection' } -- when logging result, appears have "taken" dbref data type, unsure if correct since cannot seem useful (turn ref document).

what want way represent ordered list of items multiple collections; solution fine me, far dbrefs best i've got. help?

a dbref (as explained in detail here) tuple containing objectid, collection name, , possibly database container name of referenced object in collection.

internally in mongodb server these serve no purpose , data within document. point use in drivers , odm implementations allow sort of automatic expansion issuing additional queries server in order have data elsewhere appear ordinary sub-document part of referencing document. can automatic or lazy load depending on implementation, done on wire , processed on client side. server nothing traverse or join data.

additionally, mongodb collections schemaless, there nothing in relational sense says documents in collection have have same structure.

in case of mongoose, there built in functions sort of loading convenience, , while not strictly dbref , utilizing documents different schema in same collection same means storing documents external referencing document.

it important consider data access patterns of application , not opt same sort of relational design used to. keeping in mind ever reading 1 collection @ time, desirable @ data need in single read or write, without multiple operations on wire, slow things down considerably.

in short, should consider embedding sub-documents first, , use external references best supported form when absolutely have to. application users thank in end.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -