@ifit/mongoose-clean

    1.1.0 • Public • Published

    Purpose

    A plugin for Mongoose to normalize JSON output, as well as Object output. Based on mongoose-to-json

    Contributing

    See CONTRIBUTING.md

    Usage

    Setup as a global plugin for all Mongoose schema's:

    const mongoose = require("mongoose");
    const clean = require("@ifit/mongoose-clean");
    
    mongoose.plugin(clean);

    Or for a specific (sub) schema:

    const mongoose = require("mongoose");
    const clean = require("@ifit/mongoose-clean");
    const { Schema } = mongoose;
    
    const MySchema = new Schema({});
    MySchema.plugin(clean);

    This plugin will normalize JSON output for client side applications from:

    {
      "_id": "400e8324a71d4410b9dc3980b5f8cdea",
      "__v": 2,
      "name": "Item A"
    }

    To a cleaner:

    {
      "id": "400e8324a71d4410b9dc3980b5f8cdea",
      "name": "Item A"
    }

    You can also remove private paths from the JSON:

    const mongoose = require("mongoose");
    const toJson = require("@ifit/mongoose-clean");
    const { Schema } = mongoose;
    
    const schema = new Schema({
      email: { type: String },
      password: { type: String, private: true }
    });
    
    schema.plugin(toJson);
    
    const User = mongoose.model("users", schema);
    const user = new User({ email: "test@test.com", password: "test" });
    
    console.log(user.toJSON());

    This will output:

    {
      "id": "400e8324a71d4410b9dc3980b5f8cdea",
      "email": "test@test.com"
    }

    Keywords

    none

    Install

    npm i @ifit/mongoose-clean

    DownloadsWeekly Downloads

    42

    Version

    1.1.0

    License

    ISC

    Unpacked Size

    4.71 kB

    Total Files

    6

    Last publish

    Collaborators

    • svenwaweru
    • pwbifit
    • ifit-klims
    • kyrsten.smith
    • vladyslav.miroshnychenko
    • stetsonifit
    • jduggan
    • leyla.alonso
    • awwifit
    • spencer.wadsworth
    • rexn
    • nikorablin
    • peter.ifit.com
    • jandersen
    • junchaoz
    • mario495
    • aaronl
    • cbrammer
    • thomaswilliams
    • boo-urns
    • michelle.bowser
    • robertleeplummerjr
    • mojojoejoe
    • hayden289
    • ifitshared
    • rkaneda9
    • morganrramsey
    • clodpated
    • joekuhn
    • caritochoa
    • jtuesday
    • perkyguy
    • mark-archer
    • tdfacer
    • spencer.simmons0225
    • joshifit
    • yodafred
    • jonb-ifit
    • sm-npm
    • weaster-ifit
    • cadec
    • wesleyf
    • donj
    • jamilammar
    • phild
    • dawsontoth
    • ifit-colin
    • jeffbernst
    • michaelh-ifit
    • jthurman
    • matthewpthomas
    • 32graham
    • justinwifit
    • jcalmonte
    • bikersteve
    • jayswansonce
    • lejlapri
    • barr-code
    • terrellf
    • samc-ifit
    • taylort
    • jeffy-ifit
    • jessefit
    • xbladex
    • clarcade
    • aryano
    • jnolfi
    • joshmk
    • timtifit
    • pdxmjb
    • precisiontongue
    • melissawirtz
    • sh4n3droid
    • khaifit
    • baoifit
    • hunterifit
    • tj-ro
    • jgranny
    • grantb.ifit
    • leggomygrego
    • jackswan
    • mcurcio
    • bleafman
    • scottstav
    • charlesc-ifit
    • mitchelc
    • parkerjifit
    • christinav
    • laurels
    • sgrow-ifit
    • jesshmusic
    • emiifont
    • rashaunw
    • kbgar24-ifit
    • davet2020
    • mahjongg
    • mcnewbk
    • brandonifit
    • artem_stupachenko
    • angelcontreras
    • designaroni
    • hidekys
    • andrey-bogdan
    • facundo-hm
    • terru
    • sarabadu
    • tolosa
    • agomezns
    • spatical
    • irynaalexkomar
    • williampns
    • mm-ifit
    • apukhalsky
    • bradjnewman
    • schepotin
    • icampsmith
    • michael-nock
    • dc5415
    • mikeb1772
    • ericventor
    • hurstcr
    • ramin.rabani
    • mhoagland-ifit
    • erice03
    • ariel.aguirre
    • stets10
    • niall-mahford
    • jef-hauschild
    • wisfitdev
    • talleman
    • matsalla
    • fryjus