Mongolight
This project is a wrapper for mongoskin.
Compatible versions
mongoskin >= 0.6.1.
You should use mongodb version 1.3.3. Prior mongodb versions might not work.
# Mongolight documentationInstall
$ npm install mongolight
Quick start
Get db collection
mongoskin
Seevar db = mongo;
Single file require
// file path need full pathvar path = ;var mongolight = ;//db collectionmongolight;
Skip db parameter:
mongolight need the db collection to add some dynamic methods ,you can use the global to skip the db parameter.
var path = ;// it will check global.db when you require a modelglobal_optiondb = db ;var mongolight = ;mongolight
Multi-file require
if lazy loading is true , loadFolder method only set the path to global.
var path = ;var mongolight = ;mongolight;//set the loadModel to globalgloballoadModel = mongolightloadModel;/** * when you use model class in first time,you need use loadModel method **///in index.js;module{ app;};
when lazy loading is false,you can skip the loadModel method
var path = ;var mongolight = ;mongolight; /** * skip the loadModel method **///in index.jsmodule{ app;};
Default added methods
Model.findById(id,callback) :
//use folder require ; Model
Model.findByOpt(opt,callback) :
//use folder require ; Model;
Model.list(callback) :
the same method as Model.findByOpt({},callback):
//use folder require ; Model;
Model.modify(id,opt,callback) :
//use folder require ; Model;
Model.delById(id,callback) :
//use folder require ; Model;
model.save(callback) :
save method will save the object to mongo.
//use folder require ; var model = ; model;
License
(The MIT License)
Copyright (c) 2014 gimmu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.