美文网首页
mongoose 常见问题

mongoose 常见问题

作者: 千罹 | 来源:发表于2017-05-04 19:42 被阅读33次

mongoose 会自动把表名变成复数

log => logs
reply => replies

原因:

When no collection argument is passed, Mongoose produces a collection name by passing the model name to the utils.toCollectionName method. This method pluralizes the name. If you don't like this behavior, either pass a collection name or set your schemas collection name option.

翻译过来就是:

当没有第三个参数(他们叫它collection)时,默认会给你变成复数的名字,当你不喜欢它变成复数的时候,需要加上第三个参数

var schema = new Schema({ name: String }, { collection: 'actor' });

// or

schema.set('collection', 'actor');

// or

var collectionName = 'actor'
var M = mongoose.model('Actor', schema, collectionName)

相关文章

网友评论

      本文标题:mongoose 常见问题

      本文链接:https://www.haomeiwen.com/subject/yjudtxtx.html