如何在MongoDB shell中正确使用findOne?

时间:2016-03-20 03:48:54

标签: mongodb

我是MongoDB的新手。 但是,在完成教程之后,我创建了一个数据库(比如测试),然后是一个集合,它说(名称)并且已经插入了一个数据。

现在,当我在集合上执行FindOne()时,我收到错误

C:\Users\abc>mongo
MongoDB shell version: 3.2.4
connecting to: test
> use test
switched to db test
> show collections
names
> test.names.findOne();
2016-03-20T09:16:30.366+0530 E QUERY    [thread1] ReferenceError: test is not de
fined :
@(shell):1:1

>

我在做什么错误?

提前致谢

1 个答案:

答案 0 :(得分:4)

而不是使用名称访问db,请使用db

db.names.findOne()