Q:

How to remove the deprecation warning in nodejs

I'am using mongoose-ttl node package to clear the collections. But I'am getting this warning.
(node:4768) DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.

I'am not using any methods like remove() etc.But I can't understand from where this warning is thrown.
Please suggest me any method to remove this warning.
TTL Code goes here:
var mongoose = require("mongoose");
var ttl = require('mongoose-ttl');

var OTPStore = new mongoose.Schema({
  OTPNo: {
    type: Number,
    require: true
  }
});
OTPStore.plugin(ttl, { ttl: '30m', interval: '30m'});
module.exports = mongoose.model("OTPStore", OTPStore);

Thank you.

A:

Looks like you wanna delete something from db.
const store=await OTPStore.deleteOne({_id:id}) //this will find the first one  and delete

 const store=await OTPStore.deleteMany({ _id:id })
//this will delete all. This used for properties that some of the instances have others not. For example if you had "isExpensive" property in your schema you could pass {isExpensive:true} and mongose would find all the instances that meet this criteria and remove them 

const store=await OTPStore.findByIdAndRemove(id) 
// if you notice in above examples I passed an object. But here you are already notifying mongooose that you are querying by id, so just put an id as argument

NOTE that this operations are async operations so in order to use await, make sure wrapper function should start with async function 

