Variables not defined in the mongo shell

I am trying to work with the mongo shell, and I am having problems storing the value inside the mongo shell.

when i find the user in the document i store it in doc variable

> var doc = db.users.find({"username":"anil"});

When i print doc in mongo shell i see json object

> doc
{ "_id" : ObjectId("57325aaa48d9231b11e5cb81"), "username" : "anil", "email" : "mongodb@gmail.com" }

However, when I type doc again, I see nothing. its gone. What am I doing wrong here?

> doc
>

It may be something simple, but I do not understand. Can someone point out what I'm doing wrong?

+4
source share
2 answers

mongo, mongod . mongo - mongod, , , ( , var doc = db.users. find ({ "username": "anil" }); ). , var doc = 4 , doc 4 .

, null ,

var doc = db.users.find({ "username": "anil" }); null; // doc

a ex.

enter image description here

+3

, find cursor . , _id, , . , , , , toArray, findOne

+2

All Articles