New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

baucis-decorator-deep-select

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baucis-decorator-deep-select

Adds automatic deep populate + select functionality.

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

baucis-decorator-deep-select

Adds automatic deep populate + select functionality.

Install

npm install baucis-decorators baucis-decorator-deep-select --save

Usage

Just add the decorator and it should work if you're using a version of mongoose that supports deep population. The latest release does not yet support this but 4.1 should. Until then, use npm install timbur/mongoose --save.

Example

controllers/Comment.js

var baucis = require('baucis');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;

var CommentProps = {};

CommentProps.by = {
  type: ObjectId,
  ref: 'User'
};
CommentProps.comment = {
  type: String
};
CommentProps.replies = {
  type: [{
    type: ObjectId,
    ref: 'Comment'
  }]
};

var CommentSchema = new Schema(CommentProps);
var CommentModel = mongoose.model('Comment', CommentSchema);
var CommentController = baucis.rest('Comment');

var decorators = require('baucis-decorators');
decorators.add.call(CommentController, [
  'baucis-decorator-deep-select'
]);

/**
 * Expose controller.
 */
module.exports = CommentController;

Then to select and populate some comments a few levels deep, GET a URL as follows.

From single comment:

localhost:8080/api/comments/123?select=replies.replies.replies

From query:

localhost:8080/api/comments?by=someUserId&select=replies.replies.replies

Or select certain fields:

localhost:8080/api/comments?by=someUserId&select=comment by.name by.image comment replies.comment replies.replies.comment replies.replies.replies.comment

This should pair quite well with something that might convert a GraphQL-like string to the above select parameters.

Keywords

FAQs

Package last updated on 13 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc