【问题标题】:What collection does Mongoose put things in?Mongoose 把东西放在什么系列里?
【发布时间】:2013-09-19 06:09:55
【问题描述】:

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

架构,

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

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

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

    因此,如果您要为 ProfileSchema 创建模型:

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

    集合名称是profiles;所以你会在 shell 中找到它的内容为db.profiles.find()

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

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

    将针对名为 MyProfiles 的集合。

    【讨论】:

      猜你喜欢
      • 2011-07-19
      • 1970-01-01
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 2012-05-11
      • 1970-01-01
      相关资源
      最近更新 更多