References between collections.
meteor add shuttler:ref
var b = new Mongo.Collection('a');
b.insert({ _id: 'c' });
var c = b.findOne('c');
c.Ref(); // { id: 'c', collection: 'a' }Helper added to all documents in all the collections. Generates an object-reference to that document.
The optional arguments are appended prefix to the keys in result object-reference.
c.Ref('_prefix'); // { '_prefix.id': 'c', '_prefix.collection': 'a' }Find and returns the document by reference, or undefined.
Like Shuttler.Ref, but if ref is a document returns it back.
Generates an object-reference.
If arguments is wrong, thrown Meteor.Error('unexpected reference').
- If
refisDocumentthen usesref.Ref(prefix). - If
refisRefthen addprefixto the keys inref. - If
refisStringthen userefasidfield inRefwithoutcollectionfield.
The optional arguments are appended prefix to the keys in result object-reference.
It must be a valid reference, else returns undefined.
If ref is object with string id and optional string collection, then returns true.
Ready scheme for use with packages SimpleSchema and Collection2.
- Remove dependecie from
dburles:mongo-collection-instances
Shuttler.Ref.newcollectionfield is optional- Comments