mongoose Model.findOne TypeError: Object has no method 'findOne'

后端 未结 2 1077
轻奢々
轻奢々 2021-01-18 17:39

I have a simple node.js code that uses mongoose which works when saving but doesn\'t retrieve.

.save() works, but .findOne() doesn\'t.

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 18:01

    findOne is a method on your Users model, not your user model instance. It provides its async results to the caller via callback:

    Users.findOne({field:'value'}, function(err, doc) { ... });
    

提交回复
热议问题