@reis/mongoose-only-id

3.0.0 • Public • Published

@reis/mongoose-only-id

npm version github issues

Simple Mongoose helper to safely strip objects to just an ID

Installation

You can install this package using yarn or npm.

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

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

Usage

import {onlyId} from '@reis/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 mongoose-only-id issue tracker.

License

(MIT License)

Copyright 2016-2023, Adam Reis

Package Sidebar

Install

npm i @reis/mongoose-only-id

Weekly Downloads

58

Version

3.0.0

License

MIT

Unpacked Size

5.66 kB

Total Files

7

Last publish

Collaborators

  • adamreisnz