猫鼬放什么东西? [英] What collection does Mongoose put things in?

查看:85
本文介绍了猫鼬放什么东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想浏览Mongoose存储在Mongodb中的原始数据.去哪儿了?我有一个名为Profile的模式,其中存储了多个配置文件,但是使用Mongodb shell db.Profiles.find()db.Profile.find()不会返回任何内容.

I want to browse the raw data stored in Mongodb by Mongoose. Where does it go? I have a Schema called Profile with several profiles stored in it, but using the Mongodb shell db.Profiles.find() and db.Profile.find() doesn't return anything.

模式,

var Profile = new Schema({
    username      : {type: String, index: true, required: true}
    , password      : {type: String, required: true}
    , name          : {type: String, required: true}
});

推荐答案

使用Mongoose时的默认集合名称是小写的,复数的模型名称.

The default collection name when using Mongoose is the lower-cased, pluralized model name.

因此,如果您要按以下方式为ProfileSchema创建模型:

So if you're creating your model for the ProfileSchema as:

var ProfileModel = mongoose.model('Profile', ProfileSchema);

集合名称为profiles;因此您会在外壳程序中找到它的内容为db.profiles.find().

the collection name is profiles; so you'll find its contents as db.profiles.find() in the shell.

请注意,如果您不喜欢默认行为,则可以提供自己的集合名称作为mongoose.model的第三个参数:

Note that you can provide your own collection name as the third parameter to mongoose.model if you don't like the default behavior:

var ProfileModel = mongoose.model('Profile', ProfileSchema, 'MyProfiles');

将定位到名为MyProfiles的集合.

这篇关于猫鼬放什么东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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