Skip to content

kgrgreer/foam-mongodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDAO

This repository provides a FOAM DAO which is backed by a MongoDB database, refered to as a MongoDAO. Conceptually this is very similar to JDAO which is a DAO backed by a file system journal.

Important

A MongoDB is not a journal and hence does not support models which calculate non-persistent property values during replay.

Requirements

Obviously, a MongoDB must be accessible.

MacOS

MongoDB installation

https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/

Compass UI for DB inspection

brew tap mongodb/brew
https://www.geeksforgeeks.org/how-to-install-mongodb-compass-on-macos/

Configuration

Connection settings are managed via the MongoDBService, found through CSpec service mongoDBService.
Edit the url property to add username and password.
See baseline at src/foam/dao/mongodb/services.jrl Copy and update in application deployment/, or edit at runtime. Changes to mongoDBService should take effect immediately.

Testing

Run MongoDAO specific tests cases with:
deployment/test/test.sh

NOTE: This assumes foam3 and foam-mongodb modules are co-located. In other words, your FOAM based application has cloned both foam3 and foam-mongodb at the same level.

Inclusion in Project

The repository contains two top level poms:

  1. pom: explicit configuration - configures the application for MongoDB, but leaves all EasyDAO configuration to caller. See below.
  2. pom-all: auto configuration - configures the application for MongoDB, but also refines EasyDAO such that all DAOs are configured to use MongoDAO

pom - explicite configuration

The normally named pom.js prepares the application to use MongoDB, but leaves EasyDAO configuration to the caller.
To configure EasyDAO to use a MongoDAO rather than a JDAO:
  • replace setJournalType with setDatabaseType("MONGODB")
  • replace setJournalName with setDatabaseTableName("some_unique_name")

pom-all - auto configuration

MongoDAO installs itself via refinement to EasyDAO.
A MongoDAO will be installed for each EasyDAO setup which satisfies the following:
  1. does not define an InnerDAO
  2. is not ReadOnly
  3. is not WriteOnly

DAO Stack Configuration

The DAO stack consists of an MDAO backed by the MongoDAO.
Finds and selects are served from the MDAO, puts are written to both.
This maintains the normal FOAM behaviour of runtime data superseding shipped journal data.
On startup .0 journals are read into the MDAO, and then the DB is read into the MDAO.

Ingesting Existing Data

Run script MongoDBLoad to replay runtime journals into MongoDB.

  1. Configure system to use MongoDB by referencing the mongdb pom -Pfoam-mongodb/pom (or pom-all)
  2. Start system
  3. Inspect that system is connected to MongoDB
  4. Execute script MongoDBLoad
  5. Restart

See further notes in src/foam/dao/mongodb/LoadingAgent

Cluster / Replica Sets

MongoDB supports change notification. A listener can be notified of database or collection changes in a Replica Set

see: https://www.mongodb.com/docs/drivers/java/sync/current/usage-examples/watch/

What is unknown is if the event carries information to distinguish each host, else we'll get events from ourselves.

Each MongoDAO or DDAO, on startup, could register itself with the MongoDBService. The MongoDBService could implement the watch operation and update the appropriate MDAO.

About

MongoDB Support for FOAM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •