我看到有一種SetLimit()for Find()func 的方法,但我沒有看到任何設定限制的選項FindOne(),因為我們正在搜索單個結果,FindOne()我們甚至不必限制它?自動處理限制?
嘗試使用 1options.FindOne()` 設定限制,但我看不到這樣做的方法。
uj5u.com熱心網友回復:
它沒有記錄在案,但常識Collection.FindOne()暗示Limit=1. 的回傳值Collection.FindOne()不允許訪問多個結果檔案,這就是為什么options.FindOne甚至沒有SetLimit()方法。
如果你檢查源代碼,它就在那里:
// Unconditionally send a limit to make sure only one document is returned and the cursor is not kept open
// by the server.
findOpts = append(findOpts, options.Find().SetLimit(-1))
請注意FindOptions.Limit以下檔案:
// Limit is the maximum number of documents to return. The default value is 0, which means that all documents matching the
// filter will be returned. A negative limit specifies that the resulting documents should be returned in a single
// batch. The default value is 0.
Limit *int64
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/524285.html
