Que Que - 1 year ago 45
JSON Question

How to query through a JSON file in the MongoDB client without displaying a specific field?

"Find all the books with more than 200 pages. Do not display the “Author” field."

I know how to fine all books with more than 200 pages {"Type":"Book", "Page":{"$gt": 200}}, but I'm having trouble with eliminating the "Author" field in the results. Will anyone show me how this is done? Thanks

Answer Source

From https://docs.mongodb.com/v3.0/tutorial/project-fields-from-query-results/

<field>: <0 or false> Specify the suppression of the field.

Therefore, you want something like this:

db.collection.find( {Type:"Book", Page:{"$gt": 200}}, {Author: 0} )