NodeJs猫鼬:抛出新的_mongoose.Error.OverwriteModelError(name); ^ OverwriteModelError:编译后无法覆盖_Counter模型

时间:2019-02-07 12:16:31

标签: node.js mongodb express mongoose

创建架构时猫鼬抛出错误

抛出新的_mongoose.Error.OverwriteModelError(name); ^ OverwriteModelError:编译后无法覆盖_Counter模型。

UserCredentials.js

用户架构

const mongoose = require('mongoose');
var mongooseIncrement = require('mongoose-increment');
var increment = mongooseIncrement(mongoose);
var UserCredentialsSchema = mongoose.Schema({
    fname: {
        type: String,
        required: true
    },
    lname: {
        type: String,
    },
    emailID: {
        type: String,
        unique: true
    },
    password: {
        type: String,
    },
    number_of_pets: {
        type: Number
    }
});

UserCredentialsSchema.plugin(increment, {
    type: String,
    modelName: 'UserCredentials',
    fieldName: 'userId',
    prefix: 'P-',
});

module.exports = mongoose.model("UserCredentials", UserCredentialsSchema) 

城市架构

City.js

const mongoose = require('mongoose');
var mongooseIncrement = require('mongoose-increment');
var increment = mongooseIncrement(mongoose);
var CitySchema = mongoose.Schema({
    name: {
        type: String,
        required: true
    }
})

CitySchema.plugin(increment, {
    type: String,
    modelName: 'City',
    fieldName: 'cityId',
    prefix: 'Ci-',
});

module.exports = mongoose.model("City", CitySchema)

0 个答案:

没有答案