Martian is not displaying the object stored in it from the query

I have written the query martian = db.movieDetails.find({title:"The Martian"}) this query successfully executes but when I execute martian command it returns nothing at all, no results no errors.

1

Capture

Also, I am not able to delete the _id field, the command delete martian._id executes successfully and returns true but the _id field is still there.

2

Any Helps!

Thanks,
Atul

You did not run martian = … find () like you wrote. You had pretty() at the end. It is not the same. Please refer to the pretty().

Hi @iamaeytee,

You need to append var in your query as below:

var martian = db.movieDetails.find({title:"The Martian"})

Also, keeping/removing pretty() will not affect the martian variable. The only difference is that by using pretty(), the documents stored in martian variable will be in easy-to-read format.

Please let me know, if you have any questions.

Thanks,
Sonali

2 Likes

Hey @iamaeytee

Try to run your find command with var at the front.

From the docs

By using cursor.pretty() you can set the cursor to return data in a format that is easier for humans to parse:

I have been trying different combinations with the use of var and .pretty() and I have found that is you do something like

var att3 = db.movieDetails.find({title: 'The Martian'}).pretty()

You will be able to see your results in the att3 variable.

Hi @Sonali_Mamgain,

Yeah, it worked, thanks for the help.

Thanks,
Atul

Hi, @natac13

I tried like you said, it worked.
Thanks for the help.

Regards,
Atul