【发布时间】:2019-07-07 17:38:21
【问题描述】:
有人可以帮我了解一下 mongoDB 如何有效地存储和检索数据。
在文档中,它显示了以下示例。 插入:
db.inventory.insertMany([
// MongoDB adds the _id field with an ObjectId if _id is not present
{ item: "journal", qty: 25, status: "A",
size: { h: 14, w: 21, uom: "cm" }, tags: [ "blank", "red" ] },
{ item: "notebook", qty: 50, status: "A",
size: { h: 8.5, w: 11, uom: "in" }, tags: [ "red", "blank" ] },
{ item: "paper", qty: 100, status: "D",
size: { h: 8.5, w: 11, uom: "in" }, tags: [ "red", "blank", "plain" ] },
{ item: "planner", qty: 75, status: "D",
size: { h: 22.85, w: 30, uom: "cm" }, tags: [ "blank", "red" ] },
{ item: "postcard", qty: 45, status: "A",
size: { h: 10, w: 15.25, uom: "cm" }, tags: [ "blue" ] }
])
然后检索:
db.inventory.find( { status: "D" } )
我知道它在内部使用 BSON。但是有人可以告诉我这是如何工作的(可能是上面的例子)以及如何有效地存储和检索键值对。
谢谢。
【问题讨论】:
-
这是由存储引擎处理的(可能是 WiredTiger。不太可能是 MMAPv1)。这些是谷歌搜索的关键字。