对 MongoDB 和池化感到困惑,还有 Bson 语法和文档格式
Confused about MongoDB and Pooling, also Bson syntax and Document formats
我才刚刚开始使用 MongoDB(2 小时),我对一些事情非常困惑。
首先,我了解到不需要 MongoDB 连接池,因为它已经为您完成了。这是真的吗?
其次,我在一个集合中创建配置文件,一些配置文件可能包含到期日期和密码等信息,有些则没有。是否可以将他们的文档设置为包含这些并且仍然是同一集合的成员?
第三,我正在为每个文档使用 UUID,这是检索特定文档的方法吗:
public static Document getPlayer(String uuid) {
return players.find(Document.parse("{uuid : " + uuid + "}")).first();
}
语法正确吗?我目前无法 运行 代码,因为我没有 MongoDB 服务器。
感谢您的帮助。我目前正在阅读文档并学习更多内容。
Firstly, I read that MongoDB connection pooling isn't needed as it
already does that for you. Is this true?
每当您创建 mongoClient 时,都会有一个与之关联的连接池。
您基本上不需要自己处理这些连接,而是在整个应用程序中使用单个客户端对象。您可能想在此处查看 connection 文档。
Secondly, I am creating profiles in a collection, the some of the
profiles may have information like expiry dates, and passwords, some
do not. Is it possible to just set their document to contain these and
still be a member of the same collection?
这在MongoDB中是绝对有可能的。它允许您将多态数据存储在单个集合中。
Thirdly, I'm using the UUID for each document, would this be the way
to retrieve a specific document.
看看this doc中完成的读取操作。
样本:
collection.find(
new Document("stars", new Document("$gte", 2)
.append("$lt", 5))
.append("categories", "Bakery")).forEach(printBlock);
我才刚刚开始使用 MongoDB(2 小时),我对一些事情非常困惑。
首先,我了解到不需要 MongoDB 连接池,因为它已经为您完成了。这是真的吗?
其次,我在一个集合中创建配置文件,一些配置文件可能包含到期日期和密码等信息,有些则没有。是否可以将他们的文档设置为包含这些并且仍然是同一集合的成员?
第三,我正在为每个文档使用 UUID,这是检索特定文档的方法吗:
public static Document getPlayer(String uuid) {
return players.find(Document.parse("{uuid : " + uuid + "}")).first();
}
语法正确吗?我目前无法 运行 代码,因为我没有 MongoDB 服务器。
感谢您的帮助。我目前正在阅读文档并学习更多内容。
Firstly, I read that MongoDB connection pooling isn't needed as it already does that for you. Is this true?
每当您创建 mongoClient 时,都会有一个与之关联的连接池。 您基本上不需要自己处理这些连接,而是在整个应用程序中使用单个客户端对象。您可能想在此处查看 connection 文档。
Secondly, I am creating profiles in a collection, the some of the profiles may have information like expiry dates, and passwords, some do not. Is it possible to just set their document to contain these and still be a member of the same collection?
这在MongoDB中是绝对有可能的。它允许您将多态数据存储在单个集合中。
Thirdly, I'm using the UUID for each document, would this be the way to retrieve a specific document.
看看this doc中完成的读取操作。
样本:
collection.find(
new Document("stars", new Document("$gte", 2)
.append("$lt", 5))
.append("categories", "Bakery")).forEach(printBlock);