Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Last active January 14, 2019 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melvinkcx/3d0da32ab10a55cb7b5e0d67f67fdb18 to your computer and use it in GitHub Desktop.
Save melvinkcx/3d0da32ab10a55cb7b5e0d67f67fdb18 to your computer and use it in GitHub Desktop.
Dive Into The Performance of mongoose-lean-virtuals - A Mongoose Plugin That Enables Virtuals in Lean Mode
// Full Repo: https://bitbucket.org/melvinkcx/mongoose_lean_virtuals_profiler/src/master/
const mongoose = require('mongoose');
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
const Schema = mongoose.Schema;
// Modelled after imdb title dataset
// Link: https://datasets.imdbws.com/title.basics.tsv.gz
const titleSchema = new Schema({
genres: String,
runtimeMinutes: Number,
endYear: String,
startYear: String,
isAdult: Number,
originalTitle: String,
primaryTitle: String,
tconst: String,
titleType: String
}, {
collection: 'title_basic'
});
titleSchema.virtual('isLong').get(function() {
return this.runtimeMinutes ? this.runtimeMinutes > 30 : null;
});
titleSchema.plugin(mongooseLeanVirtuals);
module.exports = titleSchema;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment