How to use set property on Mongoose?

I have a node/express server. I import mongoose, but I can't set it with useFindAndModify and useCreateIndex properties before launching the connection. Typescript claims that:

Property 'set' does not exist on type 'void'.

How to fix this? Here is my code:

import { createServer } from "http";
import Mongoose from "mongoose"

const server = createServer(app);

  .set("useFindAndModify", false)
  .set("useCreateIndex", true)
  .connect(process.env.MONGODB, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true,
    autoIndex: false,
  .then(() =>
    server.listen(process.env.PORT, () =>
      console.log(`server is listening on ${process.env.PORT}!`)
  .catch((err) => console.log("error", err));

Answers 1

  • you can use it like this way.
    mongoose.connect(uri, { useFindAndModify: false });
    Please visit this for more...

Related Articles