0.1.2 • Published 7 years ago

mongoose-scope v0.1.2

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

node-mongoose-scope

A mongoose library that sets a list of query fields in a scope

Installataion

$ npm install mongoose-scope

Usage

var mongoose = require("mongoose");
var Schema   = mongoose.Schema;
var scope    = require("mongoose-scope");

var User = new Schema({
	name: String,
	password: String,
	email: String,
	admin: Boolean,
	created: Date
}, {
	scopes: {
		bash: ["_id", "name", "email", "created"],
		detail: ["_id", "name", "email", "created", "admin"]
	}
});

User.plugin(scope);

var model = mongoose.model("User" User);

model.findByScope("bash", {name: "random"});

Documentation

.findByScope(ScopeName, Criteria optional, Options optional) => Query

executes a normal find with the selected fields defined in the scope, it takes a criteria object as optional second parameter,

NOTE: this passes an option value called $scope which contains the name of the used scope in the search

License

MIT

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago