Last active
September 28, 2017 08:16
-
-
Save pentateu/8b7dc8ee1460cf783c09cf98b06aa105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const DbService = require("moleculer-db"); | |
const mongoose = require("mongoose"); | |
const { | |
MongooseAdapter, | |
CRUDEvents | |
} = require("./common"); | |
const collection = "XXXXXX"; | |
const schema = mongoose.Schema( | |
{ | |
_id: { | |
type: String, | |
required: true, | |
alias: "id" | |
}, | |
//Sample only -> pointer with alias | |
_p_user: { | |
type: String, | |
alias: "userId" | |
}, | |
_created_at: { | |
type: Date, | |
alias: "createdAt" | |
}, | |
_updated_at: { | |
type: Date, | |
alias: "updatedAt" | |
} | |
}, | |
/* it is important to pass the collection name to schema, | |
otherwise Mongoose will base the name of the collection | |
from the model name | |
*/ | |
{collection} | |
); | |
const model = mongoose.model(collection, schema); | |
module.exports = { | |
name: `model/${collection.toLowerCase()}`, | |
mixins: [DbService, CRUDEvents], | |
adapter: new MongooseAdapter(), | |
model, | |
settings: {collection} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment