Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjirou/mongoose-id-extractor-plugin
Add {path}_id virtual-paths that is able to extract _id always
https://github.com/kjirou/mongoose-id-extractor-plugin
Last synced: 12 days ago
JSON representation
Add {path}_id virtual-paths that is able to extract _id always
- Host: GitHub
- URL: https://github.com/kjirou/mongoose-id-extractor-plugin
- Owner: kjirou
- License: mit
- Created: 2014-10-27T15:49:14.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-08-31T07:59:03.000Z (about 3 years ago)
- Last Synced: 2024-10-21T02:53:32.131Z (18 days ago)
- Language: JavaScript
- Homepage: https://www.npmjs.org/package/mongoose-id-extractor-plugin
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
mongoose-id-extractor-plugin [![Build Status](https://travis-ci.org/kjirou/mongoose-id-extractor-plugin.svg?branch=master)](https://travis-ci.org/kjirou/mongoose-id-extractor-plugin)
============================Add `{path}_id` virtual-paths as [mongoose-plugin](http://mongoosejs.com/docs/plugins.html) that is able to extract `_id` always.
## Installation
```
npm install mongoose-id-extractor-plugin
```## Examples
```
var mongoose = require('mongoose');
var idExtractor = require('mongoose-id-extractor-plugin');var commentSchema = new mongoose.Schema({
article: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Article'
}
});// Apply as mongoose-plugin
commentSchema.plugin(idExtractor, { refs:['article'] });var Comment = mongoose.model('Comment', commentSchema);
var comment = new Comment({ article:ObjectId() });
// Returns a ObjectId regardless of whether performed population.
comment.article_id;
````suffix` option:
```
schema.plugin(idExtractor, { refs:['foo'], suffix:'_object_id' });doc.foo_object_id; // Change default "_id" to "_object_id"
````map` option:
```
schema.plugin(idExtractor, {
map: {
from_path: 'to_path'
}
});doc.to_path; // _id of from_path
```