mongo-resetter
Server/Client for resetting mongo instance running in a docker container.
Server
The server loads a fixture folder into a staging mongo database. Any client can then specify which local mongodb to load the fixtures into via an HTTP interface.
var MY_FIXTURE_PATH="/fixtures";
var MY_PORT = 8010;
var ResetterServer = require("mongo-resetter").Server;
var server = new ResetterServer();
server.listen(MY_PORT);
You can also specify a default fixture path when creating the server. The client will then not need to specify which fixtures to load.
var MY_FIXTURE_PATH="/fixtures";
var MY_PORT = 8010;
var ResetterServer = require("mongo-resetter").Server;
var server = new ResetterServer(MY_FIXTURE_PATH);
server.listen(MY_PORT);
Client
Any client can reset mongo fixtures via HTTP.
Clients first specify a set of fixture to load into a staging database
curl -X POST localhost:8010 -d '{ \
"action": "LOAD", \
"fixturePath": "/path/to/fixtures"
}'
Each subsequent reset action loads those fixtures into the specified database:
```bash
curl -X POST localhost:8010 -d '{ \
"action": "RESET", \
"db": "testing-database" \
}'
Http status 200 is returned if successful.
You can also do the above via the mongo-resetter client
var ResetterClient = require("mongo-resetter").Client;
var resetter = new ResetterClient("localhost", 8010);
resetter.loadFixtures("/path/to/fixtures", function(err) {
if(err) {
return console.error(err);
}
console.log("Successfully loaded fixtures");
resetter.resetFixtures("testing-database", function(err) {
if(err) {
return console.error(err)
}
console.log("Successfully reset fixtures");
});
});