1.0.1 • Published 9 years ago
meanie-mongoose-only-id v1.0.1
@meanie/mongoose-only-id
Simple Mongoose helper to safely strip objects to just an ID
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.
Credits
- Meanie logo designed by Quan-Lin Sim
License
(MIT License)
Copyright 2016-2017, Adam Reis