//app.js
var Hapi = require('hapi'), config = require("./config"), mongoose = require("mongoose");
mongoose.connect(config.mongo.getConnectionString());
.... (start server codes)
//Schema file
"use strict";
var mongoose = require('mongoose');
var instructorSchema = require("mongoose").Schema({ fname: { type: String }, lname: { type: String }, email: { type: String }, password: { type: String }, courses: { type: mongoose.Schema.Types.ObjectId, ref: 'Course' }, registeredDate: { type: Date }});
module.exports = mongoose.model('Instructor', instructorSchema);
// file where I use mongoose schema
"use strict";
var mongoose = require('mongoose'), instructorSchema = require("../schemas/instructorSchema"), instructorModel = mongoose.model("Instructor");
function Instructor() {}
Instructor.prototype = { create: function (instructorData, callback) { var instructor = new instructorModel(instructorData); instructor.save(function () { callback(instructor._id); }); },
get: function (instructorId, callback) { instructorModel.findById(instructorId, function (err, result) { callback(result); }); },
getByData: function(instructorData, callback) { instructorModel.find(instructorData, function (err, instructor) { callback(instructor); }); },
delete: function (instructorId, callback) { instructorModel.remove({"_id": instructorId}, function (err, result) { callback(result); }); }};
module.exports = Instructor;
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.