【问题标题】:How to get collection name from a Mongoose model object如何从 Mongoose 模型对象中获取集合名称
【发布时间】:2017-09-06 00:01:48
【问题描述】:

我有一个像这样的猫鼬模型:

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

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

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

如果在回调中我只能访问“模型”引用,我如何检索集合名称。

期待类似:

model.getCollectionName();

【问题讨论】:

    标签: mongodb mongoose


    【解决方案1】:

    只需使用:

    model.collection.collectionName
    

    model.collection 中还有很多有用的信息,例如收藏选项。

    【讨论】:

    猜你喜欢
    • 2020-02-28
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 2019-07-23
    • 2014-03-03
    • 2013-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多