亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 go mongo-driver 中為 options.FindOne() 設置限制

如何在 go mongo-driver 中為 options.FindOne() 設置限制

Go
慕尼黑8549860 2023-03-07 16:45:12
我看到有一種方法可以SetLimit()用于Find()func,但我沒有看到任何設置限制的選項FindOne(),因為我們正在搜索單個結果,所以FindOne()我們甚至不必限制它?它自動處理限制?嘗試使用 1options.FindOne()` 設置限制,但我看不到這樣做的方法。
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

它沒有記錄在案,但常識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


查看完整回答
反對 回復 2023-03-07
  • 1 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號