Mongoose helper to safely strip objects to just an ID


002.4.018 days ago4 years agoMinified + gzip package size for @meanie/mongoose-only-id in KB



npm version node dependencies github issues codacy

Simple Mongoose helper to safely strip objects to just an ID



You can install this package using yarn or npm.

yarn add @meanie/mongoose-only-id

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


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
  {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.


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


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!


(MIT License)

Copyright 2016-2020, Adam Reis

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.