// 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
1条答案
按热度按时间nuypyhwy1#
虽然没有文档说明,但
Collection.FindOne()
暗示了Limit=1
的行为,这是常识。Collection.FindOne()
的返回值不给予访问多个结果文档,这就是为什么options.FindOne
甚至没有SetLimit()
方法。如果你检查源代码,它在那里:
请注意,
FindOptions.Limit
记录了以下内容: