Skip to content
Amir Hossein Seyhani edited this page Jul 21, 2017 · 2 revisions

Model

In this section we do some work with mongoose. its an ODM for mongoDB.

var mongoose = require("mongoose");

var ScoreSchema = new mongoose.Schema({
    username:String,
    score:Number
});

To define a table in mongo we define a shcema. then we define a model in order to be able to work with this document collections (e.g. we had findOne function on score model).

var scoreModel = mongoose.model("Score", ScoreSchema);
module.exports = scoreModel;

And then put this file socre.js in models directory

Clone this wiki locally