Marking documents if has link in the graph.
Algorithm for maintaining the integrity of the documents markings. The database Mongo no JOIN. Graphs can store links, but it is necessary to carry out cross-search based on the graph relations documents.
meteor add shuttler:graph-marking
In application can be many graphs and collections. In one graph can be active many selection logics. It create many different logics of link interpritation. Each interpretation can have their markings certain documents.
// Create some graph.
var graph = new Mongo.Collection('graph');
graph.attachGraph();
// Create some documents collections.
var documents = new Mongo.Collection('documents');
documents.insert({ _id: '1' });
documents.insert({ _id: '2' });
// Initialize marking targets.
var options = Shuttler.GraphMarking.byTarget;
marking = Shuttler.GraphMarking(graph, 'children', options)
.in(documents, '__graph')
.watch()
// Create one link.
var linkId = graph.link.insert(documents.findOne('1'), documents.findOne('2'));
graph.findOne(linkId);
// { _source: { id: '1', collection: 'documents' }, _target: { id: '2', collection: 'documents' } }
documents.findOne('2');
// { _id: '2', __graph: [{ id: '1', collection: 'documents'}] }
// Create not unique link.
graph.link.insert(documents.findOne('1'), documents.findOne('2'));
documents.findOne('2');
// { _id: '2', __graph: [{ id: '1', collection: 'documents'}] }
// Create second unique link.
graph.link.insert(documents.findOne('2'), documents.findOne('2'));
documents.findOne('2');
// { _id: '2', __graph: [{ id: '1', collection: 'documents'}, { id: '2', collection: 'documents'}] }
graph.getMarkingField('children', documents);
// __graph
(name: String, collection: Mongo.Collection) => String|undefined
Return undefined or field sended in graphMarking.in
wather for current graph, collection and side.
(graph: Mongo.Collection, name: String, options?: Options)
It creates a an instance of maintaining marking of documents in graph.
To the graph will be added _marking
field with object:
{ (name: String): (markingInstance: Shuttler.GraphMarking) }
In the package there are two sets of prepared options for marking.
Shuttler.GraphMarking.bySource
Shuttler.GraphMarking.byTarget
(handler: (userId, unlinked?, linked, fieldNames, modifier, options, marking) => void)
(handler: (userId, unlinked?, linked, fieldNames, modifier, options, marking) => void)
(collection: Mongo.Collection, field: String) => Shuttler.GraphMarking
It includes markings for documents in this collection in a particular field.
To the collection will be added _markedByGraphs
field with object:
{ (field: String): (markingInstance: Shuttler.GraphMarking) }
{ (collection: String): (field: String) }
() => Shuttler.GraphMarking
Run wather by graph
links sended in Shuttler.GraphMarking
constructor.
- Added
.watch
method.