gpt4 book ai didi

java - 数据如何存储在 MongoDB 表中?

转载 作者:行者123 更新时间:2023-12-02 03:22:23 29 4
gpt4 key购买 nike

我正在通过将 Mongodb 与我的 Java 应用程序集成来学习它。到目前为止,我已将 MongoDB 配置为 Windows 服务,该服务在 Windows 启动时运行,并且我能够成功连接、插入和查找与我的 Java 应用程序集成的 MongoDB 中的数据。据我所知,每个数据都作为 Key:Document 对存储在 MongoDb 中,并在没有任何预定义模式定义的情况下水平扩展。但是我仍然不清楚以下疑问:-

1)当我们说每个数据都存储为键:文档对时,那么这里的术语“键”是什么意思?它是我在数据中输入的主要值还是这个“键”意味着一些唯一的记录ID(包含像RDBMS中的随机数)。例如:-

DBCollection table = db.getCollection("employee");
BasicDBObject document = document = new BasicDBObject();
document.put("EmpId", "1001");
document.put("Name", "Vijay Kumar");
document.put("Gender", "Male");
table.insert(document);

这里,如果我没记错的话,那么 EmpId 不是这里的关键,对吧?键将是 MongoDB 表中名为“employee”的数据的唯一 ID,如“57cd9d404a85c209a42ed747”。请确认。

2)当我们说每个数据都存储为文档时,它到底意味着什么?它看起来怎么样,是结构化形式还是非结构化形式?我们不能使用 SQLDeveloper 或 Toad for RDBMS 等客户端查看存储的文档吗?

3)最后,存储和检索大量数据的速度更快

最佳答案

MongoDB 创建一个唯一的 ID 来引用表中的特定文档。

对于 1:

The key you are talkng about here is a reference variable to pick a data whenever it is called. So we say key-value pair. So EmpId is the key and 1001 is the value. Or you can view the key as the name of the column in a table and 1001 as a field.

对于 2:

The document is a collection of key-value pair. For example:

{
"EmpId", "1001",
"Name", "Vijay Kumar"
}

这可以被视为一个文档。

3 个:

To store huge data, you need to store the documents in an array form. for example you can use JSONArray object

例如:

[
{
"EmpId", "1001",
"Name", "Vijay Kumar"
},
{
"EmpId", "1002",
"Name", "Emil John"
}
]

关于java - 数据如何存储在 MongoDB 表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39438502/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com