Socket
Socket
Sign inDemoInstall

mongoose-public-id

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-public-id

Generates a public ID for your models which you can expose in your API (similar to Stripe).


Version published
Maintainers
1
0

Weekly downloads

Readme

Source

mongoose-public-id

Generates a public ID for your models which you can expose in your API.

{
  _id: '58e175ba8a7ca30011d39c8f',
  userId: '9zOROKPj4Ws4QzPaZGZK'
}

It also supports adding a prefix (similar how Stripe does it):

{
  _id: '58e175ba8a7ca30011d39c8f',
  userId: 'us_9zOROKPj4Ws4QzPaZGZK'
}

The plugin uses hashids to generate the public id based on the _id

Installing

yarn install mongoose-public-id

Usage

The following example will add a new indexed field userId to the model which will contain the public ID (eg: us_lO1DEQWBbQAACfHO) based on the _id field.

const mongoose = require('mongoose');
const publicId = require('mongoose-public-id');

const UserSchema = new mongoose.Schema({
  username: String
});

UserSchema.plugin(publicId, {
  namespace: 'us', // optional
  prefix: '_' // default value,
  fieldName: 'userId',
  index: true // default value
});

License

This project is licensed under the MIT license. See the LICENSE file for more info.

FAQs

Last updated on 07 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc