Mongodb的查询选项用于什么?

时间:2016-11-03 12:49:25

标签: java mongodb

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

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

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

setOptions需要int,我在哪里可以找到解释各种魔术数字的文档?

1 个答案:

答案 0 :(得分:3)

GetOptions() - 获取查询选项。它返回public function indexAction(Request $request) { //$name = $request->request->get('data'); //return new Response($name);//or do whatever you want with the sent value if($request->isXmlHttpRequest()){ $name = $request->request->get('data1'); If($name == 1) { return new Response('Yeap'); } else { return new Response(';('); } } return $this->render('MyIndex/Manufacturer_LIST.html.twig' ); }

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

位值对应于以下内容:

bitmask of options

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

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.

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