alex-ppg / fastify-mongoose

A Fastify plugin to connect to a MongoDB instance via the Mongoose ODM
GNU General Public License v3.0
15 stars 7 forks source link

Schema Definition Options #1

Open bstahlhood opened 5 years ago

bstahlhood commented 5 years ago

In Mongoose, you can pass options to a schema definition such as toJSON, toObject, timestamps, and id. How do you pass these with the schema definition?

medolino commented 4 years ago

You can pass schema options under models[].options.

Example:

{
  ...,
  models: [
    {
      name: "posts",
      alias: "Post",
      schema: {
        title: {
          type: String,
          required: true,
        },
        ...
      },
      // add schema configurable options
      options: {
        timestamps: true,
        ...
      }
    },
    ...
  ]
}

@alex-ppg I think it would be usefull to include this information in README.md example. If you are interested, I created a pull request https://github.com/alex-ppg/fastify-mongoose/pull/11