收集和显示记录



本章中,我们将重点关注构成了“敏捷方法”的一部分的 JSON 结构。MongoDB 是一种广泛使用的 NoSQL 数据结构,可以轻松用于收集和显示记录。

JSON Structure

步骤 1

此步骤涉及建立与 MongoDB 的连接,以便创建集合和指定的数据模型。你只需执行“mongod”命令来启动连接,并使用 mongo 命令连接到指定的终端。

Specified Data Model

步骤 2

创建一个新的数据库,以便以 JSON 格式创建记录。现在,我们正在创建一个名为“mydb”的虚拟数据库。

>use mydb
switched to db mydb
>db
mydb
>show dbs
local 0.78125GB
test 0.23012GB
>db.user.insert({"name":"Agile Data Science"})
>show dbs
local 0.78125GB
mydb 0.23012GB
test 0.23012GB

Learn Data Science in-depth with real-world projects through our Data Science certification course. Enroll and become a certified expert to boost your career.

步骤 3

创建集合是获取记录列表的必要条件。此功能有利于数据科学研究和输出。

>use test
switched to db test
>db.createCollection("mycollection")
{ "ok" : 1 }
>show collections
mycollection
system.indexes
>db.createCollection("mycol", { capped : true, autoIndexId : true, size :
 6142800, max : 10000 } )
{ "ok" : 1 }
>db.agiledatascience.insert({"name" : "demoname"})
>show collections
mycol
mycollection
system.indexes
demoname
广告