mongo-log

0.2.0 • Public • Published

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-log

Then start the server

mongo-server

This will start the server locally, defaulting to port 5000.

Node Api

First install the module

npm install mongo-log

Then 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 chronologically
  • before - A JavaScript time stamp used to filter events chronologically

Schema

{
  dataArray<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 entry
  • getEntries() - gets all log entries
  • clear() - removes all log entries
  • size() - 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 date
  • before(timeStamp) - restricts events to before a specefic date
  • query(query) - restrict based on a mongodb query to the events data

Readme

Keywords

Package Sidebar

Install

npm i mongo-log

Weekly Downloads

0

Version

0.2.0

License

ISC

Last publish

Collaborators

  • eliaslfox