Can't query mongoDB with mongoose in node.js

前端 未结 4 1973
刺人心
刺人心 2021-01-16 03:28

Suppose I have a collection in my mongoDB: db.co and only have one document:

{ \"_id\" : ObjectId(\"50d083e32cdcf7ce065b616c\"), 
  \"age\" : 22         


        
4条回答
  •  没有蜡笔的小新
    2021-01-16 03:56

    Mongoose pluralizes your model name during any CURD operation, Use this & check :

    var Co = mongoose.model('Co', coSchema, 'co'); //Even the case matters
    

    or

    var coSchema = new Schema({
        age: Number,
        friends: Array, 
        location: String,
        name: String,
        skill: Array
    }, {collection:'co'});
    var Co = mongoose.model('Co',coSchema);
    

提交回复
热议问题