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:

require("dotenv").config();
import { createServer } from "http";
import Mongoose from "mongoose"

const server = createServer(app);

Mongoose
  .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...
    [https://mongoosejs.com/docs/deprecations.html]
    

Related Articles