Can't query mongoDB with mongoose in node.js

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

    I notice your callback to find() has the following parameters : err, doc

    find() always returns an array so you really want this to be : err, docs

    OR use findOne()

    The async stuff shouldn't be a problem in the code you've posted, the nested callbacks will still be executed. Are you sure your connection is OK. I would run an open query :

    Co.find({}, function(err, docs){
     console.log(docs);
    }
    

    Just to check the collection has something in it

提交回复
热议问题