Code Monkey home page Code Monkey logo

mongoose-faker's Introduction

mongoose-faker

mongoose-faker is a small library to generate dump data using mongoose models.

Installation

npm install --save mongoose-faker

Usage

Quick usage

const faker = require('mongoose-faker');

// Creata a document and save it to the db
const student = await faker.generateObject(StudentModel, { save: true});

// You can also pass in custom fields to your model
const course = await faker.generateObject(CourseModel, {save: true, custom: { students: [ student ] }});

Using sessions

Sometimes you may create lots of data and desire to clean up the db right after you are done. You can use session to accomplish that.

const faker = require('mongoose-faker');

describe('Magic', () => {
    before(() => {
        // Tells mongoose-faker that for all objects committed to the db, keep a reference to each one of them.
        faker.newSession();
    });

    after(async () => {
        // Clean up db
        await faker.destroySession();
    });

    it('should pop magic', async () => {
        const student = await faker.generateObject(StudentModel);

        // Pop magic here
    });
})

TODO

  • Add unit tests
  • Improve documentation

Credits

Most of the code came from This repository. Thanks to Ahmed Agiza for making it available in the first place.

mongoose-faker's People

Contributors

elyx0 avatar tnsengimana avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.