How to get a collection name from a Mongoose model object

I have such a mongoose model:

var mongoose = require("mongoose");
var Schema = mongoose.Schema;

let schema = new Schema({
    test: String
}, {
    collection: "test"
});

let model = mongoose.model("TestModel", schema);

How to get the name of the collection if in the callback I have access only to the reference link.

Expecting something like:

model.getCollectionName();
+4
source share
1 answer

Just use:

model.collection.collectionName

You also have a lot of useful information in model.collection, such as collection options.

+8
source

Source: https://habr.com/ru/post/1674514/


All Articles