node.js - 關(guān)于mongoose方法的回調(diào)函數(shù)的參數(shù)問題,如何知道參數(shù)個(gè)數(shù)以及參數(shù)代表什么含義呢?
問題描述
mongoose中方法幾乎都有回調(diào)函數(shù),但是回調(diào)函數(shù)的參數(shù)信息查詢不到,所以請問如何可以查到呢?
問題解答
回答1:好好查文檔應(yīng)該能找到。我不使用mongoose驅(qū)動(dòng)因此對它并不是十分熟悉,以下信息僅供參考:http://mongoosejs.com/docs/qu...
Anywhere a callback is passed to a query in Mongoose, the callback follows the pattern callback(error, results). What results is depends on the operation: For findOne() it is a potentially-null single document, find() a list of documents, count() the number of documents, update() the number of documents affected, etc. The API docs for Models provide more detail on what is passed to the callbacks.
回答2:看文檔
用TypeScript:
mongsoose的官方文檔還是蠻清晰的啊,你可以參考官方文檔。一般查詢語句的話回調(diào)函數(shù)是error和document兩個(gè)屬性。每一個(gè)模塊的內(nèi)部實(shí)現(xiàn)在官方文檔都是能看到的,所以想知道傳入幾個(gè)參數(shù)然后不同參數(shù)的處理情況都是很好查看的。
