0.2.0 • Published 9 years ago
mongo-log v0.2.0
Mongo Log
Mongo log is an append only log management system built on top of mongodb. It can be used to provide either a node module or a rest api.
Setup
Rest Api
First install the module globally
npm install --global mongo-logThen start the server
mongo-serverThis will start the server locally, defaulting to port 5000.
Node Api
First install the module
npm install mongo-logThen require it
const MongoLog = require("mongo-log")Scheme
The schema for an event item is
type Event = {
_id: String,
time: Number,
data: Object
}Rest Api
GET /api/log
Returns a list of every event
URL Params
after- A JavaScript time stamp used to filter events chronologicallybefore- A JavaScript time stamp used to filter events chronologically
Schema
{
data: Array<Event>
}POST /api/log
Adds a new event
Schema
{
result: "Log entry added"
}DELETE /api/log
Clears all log events
Schema
{
result: "Logs cleared"
}Node Module
The node node module exports a single class that is constructed with a mongodb connection.
cosnt mongoLog = new MongoLog(db)Regular Methods
all methods return promises
addEntry(data)- adds a new log entrygetEntries()- gets all log entriesclear()- removes all log entriessize()- gets the number of log entries
Filtering Methods
filtering methods return a new instance of MongoLog, which regular methods or other filtering methods can then be called on.
after(timeStamp)- restricts events to after a specefic datebefore(timeStamp)- restricts events to before a specefic datequery(query)- restrict based on a mongodb query to the events data