GithubHelp home page GithubHelp logo

mongoose-filter-denormalize's Issues

Always returns '_id' - Why?

There is code specifically to let _id pass through the filter. What is the thinking behind this?

filters = filters ? filters.concat('_id') : filters; // Always send _id property

If you wish to use slugs or other unique tags to reference your objects, internal id's are unnecessary to expose to the public.

In my case, I am exposing the id but wish to expose it as 'id' not '_id'. This is easily achieved on the schema with the following snippet (Mongoose automatically makes 'id' a virtual schema object, which is purely an ObjectId pre-casted to a hex string):

// Set virtuals to true so they are evaluated on all items in a collectio
MySchema.set('toJSON', {
    virtuals: true
});

MySchema.plugin(Filter, {
    readFilter: {
        "public": ['id', 'title', 'location', 'description', 'active']
    }
});

Denormalize doesn't work for me in latest build.

EDIT:

It turns out this is a Mongoose 3.8 compatibility issue. Fixes are required to support the new Mongoose query builder mquery.

Not a bug, just needs updating.

Hi,

Using similar code to the example, I still can't get denormalize to work. I can however get Filter to work on it's own.

Route:

var CameraModel = require('../../../lib/models/camera');

exports.get = function(req, res){
    CameraModel.findById( req.params.id ).denormalize( {filter: 'public'} ).run( function(err, camera) {
        if (err) return res.json(500, { status: 'An error occurred' });
        return res.json(200, {success: true, data: camera});
    });
};

Schema:

var Mongoose = require('mongoose'),
    Schema = Mongoose.Schema,
    Filter = require('Mongoose-filter-denormalize').filter,
    Denormalize = require('Mongoose-filter-denormalize').denormalize;


var CameraSchema = new Schema({
    location:       { type: Mongoose.Schema.Types.ObjectId, ref: 'Location' },
    title:          { type: String, required: true },
});


CameraSchema.plugin(Filter, {
    readFilter: {
        "public": ['title', 'location']
    },
    sanitize: true
});


CameraSchema.plugin(Denormalize, {
    defaults: ['location']
});

module.exports = Mongoose.model('Camera', CameraSchema);

Resulting error:

TypeError: Object #<Query> has no method 'denormalize'
at exports.get (/Users/usernm/Dropbox/Sites/projName/releaseName/routes/v1/camera/index.js:32:43)
at callbacks (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/lib/router/index.js:164:37)
at param (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/lib/router/index.js:138:11)
at param (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/lib/router/index.js:135:11)
at pass (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/lib/router/index.js:173:5)
at Object.router (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/lib/router/index.js:33:10)
at next (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at Object.methodOverride [as handle] (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:48:5)
at next (/Users/usernm/Dropbox/Sites/projName/releaseName/node_modules/express/node_modules/connect/lib/proto.js:193:15)

package.json

{
  "name": "Project...",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "express": "~3.4.7",
    "mongoose": "~3.8.3",
    "mongoose-filter-denormalize": "~0.2.1"
  }
}

Working filtering query:

    CameraModel.findById( req.params.id, CameraModel.getReadFilterKeys('public'), function(err, camera) {
        if (err) return res.json(500, { status: 'An error occurred' });
        return res.json(200, {success: true, data: camera});
    });

Any ideas? Is it me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.