As the title says, I want to add extra methods to the mongodb drivers.
Currently i’m using a collection instance to to insert, delete documents in my database like this:
// collName.js
const client = new MongoClient(uri);
const db = client.db("dbName");
export default const collection = db.collection("collName");
//file1.js
import collection form "collName.js"
cont data = [ ]
collection.insertMany(data)
But I would like to add some methods to the collection instance, to do something like this:
collection.modifiedInsertMany(data)
I guess, I could create my own class:
class myCollection {
col = db.collection("collName");
function modifiedInsertMany(data) {
// do stuff with data
return col.insertMany(data);
}
}
But if i did that I would have to rewrite every single method of the original mongodb.Collection, isn’t that correct?
If possible, I want to keep all the methods of the mongodb.Collection and just add a couple of my methods.
Is it possible to do that?