crul:meteor-external-mongo-db

v0.3.0Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

meteor external mongo db Build Status

external mongo db connector for angular meteor apps

meteor add crul:meteor-external-mongo-db

quick start

1if (Meteor.isServer) {
2    import { ExternalMongoDb } from 'meteor/crul:meteor-external-mongo-db';
3    let externalMongoDb = new ExternalMongoDb();
4    externalMongoDb.connect('mongodb://127.0.0.1:27017/dbName');
5    externalMongoDb.disconnect('dbName');
6}

dependencies

  • ecmascript
  • underscore
  • random

api

this packages exports ExternalMongoDb class (server side) which has 2 methods:

  • connect(dbUrl): it publish:

    • a collection named 'dbName-collections' with the collections of the remote DB
    • all the server collections with plain names, find function signature: find(where, options)
  • disconnect(dbName): not working :(

! because collections are published with plain names, remote DB should have no collection with same name than collections in local DB

roadmap

  • add configuration/settings (optional prefix for collections)
  • disconnect / reconnect

example project instructions

  • meteor configuration

    meteor create meteorTestApp
    cd meteorTestApp
    meteor add sesion
    meteor add crul:meteor-external-mongo-db
    
  • add main.js code to server:

    1import { Meteor } from 'meteor/meteor';
    2import { ExternalMongoDb } from 'meteor/crul:meteor-external-mongo-db';
    3
    4Meteor.startup(() => {
    5    var externalMongoDb = new ExternalMongoDb();
    6    externalMongoDb.connect('mongodb://127.0.0.1:27017/dbName');
    7});
  • add main.js code to client:

    1import { Meteor } from 'meteor/meteor';
    2import './main.html';
    3
    4Meteor.subscribe('umdm-collections');
    5let Collections = new Meteor.Collection('umdm-collections');
    6let Collection;
    7let collections = {};
    8
    9Template.body.helpers({
    10    collections() {
    11        return Collections.find({});
    12    },
    13    collection() {
    14        return Collection.find({});
    15    },
    16    collectionLoaded() {
    17        return Session.get('collectionLoaded');
    18    }
    19});
    20
    21Template.body.events({
    22    'click .collection'(event, instance) {
    23        let collectionName = $(arguments[0].currentTarget).html();
    24
    25        Meteor.subscribe(collectionName);
    26        collections[collectionName] = collections[collectionName] || new Meteor.Collection(collectionName) 
    27        Collection = collections[collectionName];
    28        Session.set('collectionLoaded', true);
    29    }
    30});
  • add main.html code to client:

    1<body>        
    2    <div style="border: solid 1px #000">
    3    {{#each item in collections}}
    4        <button class="collection">{{item.name}}</button>
    5    {{/each}}
    6    </div>
    7
    8    {{#if collectionLoaded}}
    9        <div style="border: solid 1px #666">
    10        {{#each item in collection}}
    11            <div class="feed">{{item._id}}</div>
    12        {{/each}}
    13        </div>
    14    {{/if}}
    15</body>