Skip to content

Instantly share code, notes, and snippets.

@pentateu
Last active September 28, 2017 08:16
Show Gist options
  • Save pentateu/8b7dc8ee1460cf783c09cf98b06aa105 to your computer and use it in GitHub Desktop.
Save pentateu/8b7dc8ee1460cf783c09cf98b06aa105 to your computer and use it in GitHub Desktop.
"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