Can't query mongoDB with mongoose in node.js

前端 未结 4 1943
刺人心
刺人心 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:53

    Mongoose pluralizes the lower-cased model name when determining the collection name to use. So with a model name of 'Co' it's going to be looking in the cos collection by default.

    To override the default and align with your existing co collection:

    var Co = mongoose.model('Co', coSchema, 'co');
    

提交回复
热议问题