mongo shell - 访问数据库集合

bmc*_*bmc 3 mongodb

问题

我已经mongo在我的 MAC OSX 环境中成功启动了shell。我正在为以下链接和文档提供资源,以找出进入数据库,然后是集合,然后查询集合中的文档的简单任务: 从 MongoDB 文档访问数据库访问集合和文档,在 Stackoverflow 上,以及访问Tutorials Point的合集

我通过PyMongoAPI创建并加载了数据库。这成功地创建了一个名为 的数据库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
> 
Run Code Online (Sandbox Code Playgroud)

并且income肯定是我创建的集合,用于存储来自 UCI 的成人收入存储库的行。如mongo db 文档中所述

db.collection.find(query, projection)
Run Code Online (Sandbox Code Playgroud)

是查询集合的语法。

我最好的尝试

> 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
> 
Run Code Online (Sandbox Code Playgroud)

任何反馈都是有帮助的。

小智 9

问题是你没有做

db.collection.find(query, projection)
Run Code Online (Sandbox Code Playgroud)

要查询要从命令中删除数据库名称的集合,即

use UCI-Database
db.income.find({"age":35})
Run Code Online (Sandbox Code Playgroud)