mongoose.helper
v0.0.1
Published
API for mongoose scheme
Downloads
5
Readme
mongoose.helper
Simple mongoose models api Created by Mikelis Asnins E-mail: [email protected]
Developed for commercial mass e-mail sending application (not spammer :D, application is usded for sending reminders, invoices, etc.)
addSchema('name', MongooseSchema) -> adds mongoose schema to list, for later use
create(Schema or 'name', {data}, callback) -> create record in db
//validateAndCreate -> validate data and create record (WIP)
list(Schema or 'name', callback) -> list all data
remove(Schema or 'name', callback) -> remove data
find(Schema or 'name', {filter}, callback) -> find record
findByID(Schema or 'name', id, callback) -> find record by id
findOne(Schema or 'name', filter, callback) -> return one record
paginate(Schema or 'name', pageSize, pageNumber, callback) -> simple mongoDB paginator. pageSize --> record count in one page, pageNumber --> current page number
count(Schema or 'name', filter, callback) -> return record count
exists(Schema or 'name', filter, callback) -> return true if record exists
more features comming soon!
example:
var api = require('mongoose.helper');
api.addSchema('tasks', require('../models/task'));
api.addSchema('spools', require('../models/spools'));
api.create('tasks', {
name: 'test',
created_by: 'Mikelis'
}, function (err, doc) {
if (!err) {
console.log('success');
} else {
console.log(err);
}
});
api.list('spools', {
name: 'test',
created_by: 'Mikelis'
}, function(err, doc){
if (!err) {
console.log(doc);
} else {
console.log(err);
}
});