You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GroundDB is a fast and thin layer providing Meteor offline database - Taking cloud data to the ground.
Features
This version of GroundDB is a caching only storage - meaning it does not support resuming of method calls/cross tab updates etc. But it's faster and async supporting local storages like:
localstorage
indexeddb
websql
* SQLite (on cordova)
It's using localforage with some minor modifications - hopefully we can use localForage via npm in the future
Ground.Collection is client-side only and depends on LocalCollection for now
Get documents and updates from a Meteor Mongo Collection via DDP
foo=newGround.Collection('test');foo.observeSource(bar.find());Meteor.setTimeout(()=>{// Stop observing - keeping all documents as isfoo.stopObserver();},1000);
Limiting the stored data
If you want to clean up the storage and eg. have it match the current subscription, now you can:
foo.keep(bar.find());
This will discard all documents not in the subscribed data
Limit the data stored locally
foo.keep(bar.find({},{limit: 30}));
This will discard all but 30 documents
Limit the data stored locall using multiple cursors
This will keep at max 60 documents 30 documents of each type "a"/"b"
Clear the storage
foo.clear();
This will empty the in memory and the local storage
Need a near backwards compatible solution?
This example behaves much like the previous version of ground db regarding caching a Mongo.Collection - This class inforces a manual clean up. Calling removeLocalOnly() will keep only the documents in the Mongo.Collection.
GroundLegacy={Collection: classGroundLegacyextendsGround.Collection{constructor(collection,options){if(!(collectioninstanceofMongo.Collection)){thrownewError('GroundLegacy requires a Mongo.Collection');}if(options.cleanupLocalData!==false){thrownewError('GroundLegacy requires cleanupLocalData to be false');}// Create an instance of ground dbsuper(collection._name);this.mongoCollection=collection;collection.grounddb=this;// Observe on the whole collectionthis.observeSource(collection.find());// Store supercollection.orgFind=collection.find;collection.orgFindOne=collection.findOne;// Overwrite collection finds using the grounded datacollection.find=(...args)=>{returnthis.find(...args);};collection.findOne=(...args)=>{returnthis.findOne(...args);};}removeLocalOnly(){// Remove all documents not in current subscriptionthis.keep(this.mongoCollection.orgFind());}},};