@meanie/mongoose-only-id

2.4.0 • Public • Published

@meanie/mongoose-only-id

npm version node dependencies github issues codacy

Simple Mongoose helper to safely strip objects to just an ID

Meanie

Installation

You can install this package using yarn or npm.

#yarn
yarn add @meanie/mongoose-only-id

#npm
npm install @meanie/mongoose-only-id --save

Usage

const onlyId = require('meanie-mongoose-only-id');

//Objects are stripped to only ID
onlyId({id: '123', name: 'Name'}); //'123'
onlyId({_id: new ObjectId('123'), name: 'Name'}); //'123'

//Also works on arrays
onlyId([
  {id: '123', name: 'Item 1'},
  {_id: new ObjectId('123'), name: 'Name'},
]); //['123', '123']

//Simple values are retained
onlyId('123'); //'123'
onlyId(123); //123

Issues & feature requests

Please report any bugs, issues, suggestions and feature requests in the @meanie/mongoose-only-id issue tracker.

Contributing

Pull requests are welcome! If you would like to contribute to Meanie, please check out the Meanie contributing guidelines.

Sponsor

This package has been kindly sponsored by Hello Club, an all in one club and membership management solution complete with booking system, automated membership renewals, online payments and integrated access and light control. Check us out if you happen to belong to any kind of club or if you know someone who helps run a club!

License

(MIT License)

Copyright 2016-2020, Adam Reis

Readme

Keywords

Package Sidebar

Install

npm i @meanie/mongoose-only-id

Weekly Downloads

10

Version

2.4.0

License

MIT

Unpacked Size

6.7 kB

Total Files

7

Last publish

Collaborators

  • adamreisnz