我有一个蒙古模式,就像这样:
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
let schema = new Schema({
test: String
}, {
collection: "test"
});
let model = mongoose.model("TestModel", schema);
如果在回调中我只能访问“model”引用,那么如何检索集合名称?
期望类似于:
model.getCollectionName();
最佳答案
仅使用:
model.collection.collectionName
您在
model.collection
中也有很多有用的信息,例如收集选项。关于mongodb - 如何从Mongoose模型对象获取集合名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43331706/