Mongoose always returning an empty array NodeJS

后端 未结 5 1094

I have tried using find and findOne and both are not returning a document. find is returning an empty array while findOne

5条回答
  •  滥情空心
    2020-11-22 10:38

    The call to mongoose.model establishes the name of the collection the model is tied to, with the default being the pluralized, lower-cased model name. So with your code, that would be 'models'. To use the model with the files collection, change that line to:

    var Model = mongoose.model("Model", fileSchema, "files");
    

    or

    var Model = mongoose.model("file", fileSchema);
    

提交回复
热议问题