java - Mongodb 的查询选项有什么用?

标签 java mongodb

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

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

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

setOptions 需要一个 int,我在哪里可以找到解释各种魔数(Magic Number)作用的文档?

最佳答案

GetOptions() - 获取查询选项。它返回选项的位掩码

来自GetOptions()this文档:您可以看到标志(查询选项的位 vector )。

位值对应如下:

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

关于java - Mongodb 的查询选项有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40401953/

相关文章:

mongodb - Mongo 使用 $project 聚合重命名字段?

java - Gson java.lang.IllegalArgumentException : No time zone indicator

MongoDB fatal error : runtime: out of memory

可枚举的 Ruby Mongo gem 批量插入

javascript - 过滤以不在结果数组中包含匹配值

java - 如何在 Android 中舍入十进制数

java - 使用 Selenium -Browserstack 设置 PAC 文件代理

java - 数组列表错误

java - 将多个图像写入 ServletOutputStream?

node.js - Mongoose 获取除一个之外的随机元素