问题描述
我想浏览 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
;所以你会在 shell 中找到它的内容为 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
的集合.
would target a collection named MyProfiles
.
这篇关于Mongoose 把东西放在什么集合里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!