From d513b23be26bda40d40ec43258345af6e34cfdfd Mon Sep 17 00:00:00 2001 From: Eugene Sokolov Date: Fri, 4 Dec 2020 00:51:16 +0300 Subject: docs: add example client usage --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7a6490..92f42f9 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,16 @@ Cron-based job scheduler which persists events to MongoDB ## Usage example ```js -// Define schema for event context and wrap it into a model +const mongoose = require('mongoose'); +const { Client, Scheduler } = require('mongo-cronjob'); + +// Define schema for event context const contextSchema = new Schema({ message: String }); -const EventModel = model('Event', contextSchema); + +// Initialize client with existing connection +const client = new Client(mongoose.connection, contextSchema); +const EventModel = client.Event; +const LogModel = client.Log; // Initialize scheduler const scheduler = new Scheduler(EventModel); -- cgit v1.2.3