如何从猫鼬模型对象获取集合名称 [英] How to get collection name from a Mongoose model object

查看:54
本文介绍了如何从猫鼬模型对象获取集合名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a mongoose model like so:

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

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

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

如果在回调中我只能访问模型"引用,那么如何检索集合名称.

How do I retrieve the collection name if in a callback I only have access to the "model" reference.

期望如下:

model.getCollectionName();

推荐答案

只需使用:

model.collection.collectionName

model.collection中您还具有很多有用的信息,例如收集选项.

You also have a lot of usefull informations in model.collection such as collection options.

这篇关于如何从猫鼬模型对象获取集合名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆