0.1.3 • Published 9 months ago

mongoose-actions v0.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

mongoose-actions

mongoose-actions is a Mongoose plugin that tracks changes to documents and logs actions such as creation, updates, and deletions.

Installation

npm install mongoose-actions

Usage

Plugin Setup

First, apply the plugin to your Mongoose schema:

import mongoose from 'mongoose';
import mongooseActionsPlugin from 'mongoose-actions';

const testSchema = new mongoose.Schema({
  name: String,
  description: String,
  untracked: String,
});

testSchema.plugin(mongooseActionsPlugin, { fields: ['name', 'description'] });

const TestModel = mongoose.model('Test', testSchema);

Example

Here is an example of how to use the plugin:

import mongoose from 'mongoose';
import TestModel from './path-to-your-model';

async function run() {
  const testDoc = new TestModel({ name: 'Test', description: 'Initial description' });
  await testDoc.save();

  testDoc.description = 'Updated description';
  const user = new mongoose.Types.ObjectId();
  await testDoc.modifiedBy(user).save();
  
  // the listActions method returns an array of actions
  const actions = await testDoc.listActions({limit: 10, skip: 0});
  console.log(actions);
}


run();

Running Tests

To run tests, use the following command:

npm test

License

This project is licensed under the ISC License.

0.1.2

9 months ago

0.1.1

10 months ago

0.1.3

9 months ago

0.1.0

10 months ago

0.0.11

10 months ago

0.0.12

10 months ago

0.0.13

10 months ago

0.0.14

10 months ago

0.0.15

10 months ago

0.0.16

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago