how to save a result from a mongodb query into a javascript variable?

后端 未结 2 1020
广开言路
广开言路 2021-01-14 00:33

there are some questions here regarding how to save a result from a query into a javascript varialbe, but I\'m just not able to implement them. The point is that I have a mu

2条回答
  •  礼貌的吻别
    2021-01-14 01:37

    After some time figuring out, I got the solution. here it is, for future reference:

    var cursor = db.drives.find({},{"_id":1}).sort({"driveDate":1}).limit(1)
    

    Then I can get the document from the cursor like this

    var myDate = cursor.next()
    

    That's it. Thanks for your help

提交回复
热议问题