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.
A MongoDB is not a journal and hence does not support models which calculate non-persistent property values during replay.Obviously, a MongoDB must be accessible.
MongoDB installation
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/Compass UI for DB inspection
brew tap mongodb/brewhttps://www.geeksforgeeks.org/how-to-install-mongodb-compass-on-macos/
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.
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.
The repository contains two top level poms:
- pom: explicit configuration - configures the application for MongoDB, but leaves all EasyDAO configuration to caller. See below.
- pom-all: auto configuration - configures the application for MongoDB, but also refines EasyDAO such that all DAOs are configured to use MongoDAO
To configure EasyDAO to use a MongoDAO rather than a JDAO:
- replace setJournalType with setDatabaseType("MONGODB")
- replace setJournalName with setDatabaseTableName("some_unique_name")
A MongoDAO will be installed for each EasyDAO setup which satisfies the following:
- does not define an InnerDAO
- is not ReadOnly
- is not WriteOnly
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.
Run script MongoDBLoad to replay runtime journals into MongoDB.
- Configure system to use MongoDB by referencing the mongdb pom -Pfoam-mongodb/pom (or pom-all)
- Start system
- Inspect that system is connected to MongoDB
- Execute script MongoDBLoad
- Restart
See further notes in src/foam/dao/mongodb/LoadingAgent
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.