【问题标题】:What are Mongodb's query options used for?Mongodb 的查询选项有什么用?
【发布时间】:2016-11-03 21:07:50
【问题描述】:

Java Mongodb 客户端公开了两组选项:

  • 来自getOptions,文档称其用于默认查询选项。
  • 来自getMongoClientOptions,文档说这与客户端和集群之间的连接有关。

查询选项是否继承自客户端选项?

setOptions 需要 int,我在哪里可以找到解释各种幻数作用的文档?

【问题讨论】:

    标签: java mongodb


    【解决方案1】:

    GetOptions() - 获取查询选项。它返回bitmask of options

    GetOptions()this 文档中:您可以看到标志(查询选项的位向量)。

    位值对应如下:

    0 is reserved. Must be set to 0.
    1 corresponds to TailableCursor. Tailable means cursor is not closed when the last data is retrieved. Rather, the cursor marks the final object’s position. You can resume using the cursor later, from where it was located, if more data were received. Like any “latent cursor”, the cursor may become invalid at some point (CursorNotFound) – for example if the final object it references were deleted.
    2 corresponds to SlaveOk.Allow query of replica slave. Normally these return an error except for namespace “local”.
    3 corresponds to OplogReplay. Internal replication use only - driver should not set.
    4 corresponds to NoCursorTimeout. The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
    5 corresponds to AwaitData. Use with TailableCursor. If we are at the end of the data, block for a while rather than returning no data. After a timeout period, we do return as normal.
    6 corresponds to Exhaust. Stream the data down full blast in multiple “more” packages, on the assumption that the client will fully read all data queried. Faster when you are pulling a lot of data and know you want to pull it all down. Note: the client is not allowed to not read all the data unless it closes the connection.
    7 corresponds to Partial. Get partial results from a mongos if some shards are down (instead of throwing an error)
    8-31 are reserved. Must be set to 0.
    

    GetMongoClientOptions() - 获取此客户端用于连接服务器的选项。它返回各种设置来控制 MongoClient 的行为。以下是上述方法返回的 MongoClientOptions 方法。例如:

    getClusterListeners()  
    getConnectionsPerHost()  
    getConnectTimeout()  
    getLocalThreshold()
    

    您可以在以下链接中查看其他方法: http://api.mongodb.com/java/current/com/mongodb/MongoClientOptions.html

    【讨论】:

      猜你喜欢
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多