Can I use minimongo without MongoDB?

I am building a Meteor app (for deploy as an Android app) for a hosting environment that does not have MongoDB, and so I’m using a PHP/SQL backend/database. I’m wondering if minimongo requires MongoDB installed as a dependency. In other words, can I use minimongo even if MongoDB isn’t installed?

Right now, I am retrieving data from my SQL database in Meteor.isServer, then saving it in a callback to a Meteor session variable, but I find that my app’s templates and data are not synchronized (things load slowly) so I think this approach is incorrect. Storing my retrieved data in Meteor session variables isn’t working well because the data does not persist between pages after I’m routed to a different page. The overall result is that the app is slow and does not retrieve and display data consistently across pages.

I’m wondering if the solution is retrieving the data and caching it in Meteor’s minimongo so that the Meteor.isClient can use the data more efficiently. If I do use it, will it affect my deploying it as an Android application in any way?

A related question is, is minimongo simply a local collection on the client that does NOT require MongoDB installation on the host server? If so, this means I could potentially use minimongo. The official documentation on Meteor says “If you just want to store and query some data, use the minimongo package directly. See the API reference on the main Meteor docs page.” but doesn’t say whether or not minimongo actually requires MongoDB to be installed.

Thanks!

I’ll be honest with you. If you’re using a SQL backend, you’re tossing out the best part of meteor, which is magical awesome oplog tracking. You’re also deploying for mobile, which Cordova is good at, but not great. You’d be better off building on react native. If you need a client cache, consider something like lokka, redux, adrenaline, or relay (in order of easy to hard). I’m guessing this is an MVP, which means you can probably do without a client cache for awhile. Saving a couple bytes over the wire isn’t worth a week of headaches.

That said, sure, you can use it. The EJSON implementation isn’t that inefficient. Fetch your data, cram it in a local minimongo collection & call it a day :smile:

[quote=“mattkrick, post:2, topic:17004”]Fetch your data, cram it in a local minimongo collection & call it a day
[/quote]

Thanks @mattkrick! I was wondering though, you mention using the local minimongo collection. While I can use minimongo in development in localhost, I’m wondering what happens on deploy of my production app. i.e. would it possible for me to use minimongo even if the webhost/server doesn’t have or cannot support MongoDB? I guess what I’m asking is “does minimongo depend on MongoDB being installed?”

Check out the minimongo source code, it’s very readable. It’s basically a glorified in-memory object that lives on the client. You can do anything you want with it.

You can, but I would advise against it. As soon as your clientside collection grows beyond a few hundred documents, it gets slow. You can get way better performance by putting all your data in a reactiveVar and then query that with lodash.

To answer your question, yes you can use minimongo without MongoDB, you just need to understand how DDP works and how to publish the data in the right format. These docs should help you out:

http://docs.meteor.com/#/full/meteor_publish

What you want to pay close attention to are the low-level this.added, this.changed, this.removed and this.ready APIs of the publication.

Here’s an example:

// client code only
var myClientCollection = new Mongo.Collection('myStore');

// server code only
Meteor.publish('data', function() {
  this.added('myStore', 'id1', { hello: 'world' });
  this.added('myStore', 'id2', { hello: 'dude' });
  // Typically you probably will poll a rest API endpoint

  // Call this to indicate to the client that you've completely subscribed
  this.ready();

  // Do clean up here when your subscription stops
  this.onStop(() => {
    // Stop polling your rest API or something like that
  });
});

// back to client code
Meteor.subscribe('data');
console.log(myClientCollection.find().fetch());
// [{ _id: 'id1', hello: 'world' }, { _id: 'id2', hello: 'dude' }]

here’s a good article explaining how to piggyback the pub/sub system to publish data from any source you want