问题
我已经在我的 MAC OSX 环境中成功启动了 mongo
shell。我正在查阅以下链接和文档,以找出进入数据库、进入集合、查询集合中文档的简单任务:
来自 MongoDB 文档的访问数据库,
来自 Stackoverflow 的访问集合和文档,以及来自 Tutorials Point 的访问集合。
我通过 PyMongo
API 创建并加载了数据库。这成功创建了一个名为 UCI-Database
的数据库,一个名为 income
的集合,并填充了一些来自 .csv
文件的文档(行)。
到目前为止...
这是我的结果...
Blakes-MacBook-Pro:nosql bmc$ mongo 127.0.0.1:27017
MongoDB shell version v3.4.4
connecting to: 127.0.0.1:27017
MongoDB server version: 3.4.4
Server has startup warnings:
2017-05-16T12:22:10.147-0400 I CONTROL [initandlisten]
2017-05-16T12:22:10.147-0400 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-05-16T12:22:10.147-0400 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-05-16T12:22:10.147-0400 I CONTROL [initandlisten]
2017-05-16T12:22:10.147-0400 I CONTROL [initandlisten]
2017-05-16T12:22:10.147-0400 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> show dbs
UCI-Database 0.006GB
admin 0.000GB
local 0.000GB
test-database 0.000GB
> use UCI-Database
switched to db UCI-Database
> show collections
income
profiles
>
这里的income
是我创建用来存储来自UCI成年人收入数据集的行的集合。根据MongoDB文档中的说明:
db.collection.find(query, projection)
这是用于查询集合的语法。
我的最佳尝试
> db.UCI-Database.income.find({"age":35})
2017-05-16T16:38:00.846-0400 E QUERY [thread1] ReferenceError: Database is not defined :
@(shell):1:1
>
任何反馈都很有帮助。
count
和distinct
之类的东西? - bmc