Any alternative for '<Modelname>.find()' function in mongoose

Hi @Ankit_Patnaik,

Welcome to the MongoDB Community forums :sparkles:

The usage of callback functions has been deprecated in Mongoose 7.x. Therefore, if you were using these functions with callbacks, it is recommended to use either async/await or promises. If async functions do not meet your requirements, you can go for promises.

// Before
conn.startSession(function(err, session) {
  // ...
});

// After
const session = await conn.startSession();
// Or:
conn.startSession().then(sesson => { /* ... */ });

I hope it helps!

Best,
Kushagra

1 Like