mongo shell - 访问数据库集合



问题

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

我通过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成人收入存储库中的行。如 mongo db 文档中所述:

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
> 

任何反馈都是有帮助的。

问题是你没有做

db.collection.find(query, projection)

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

use UCI-Database
db.income.find({"age":35})

最新更新