Field Selection in mongo db

MongoDB queries can take some additional arguments. For example, it's possible to request only certain fields be returned. If we just wanted the social security numbers of users with the last name of 'Smith,' then from the shell we could issue this query:
  // retrieve ssn field for documents where last_name == 'Nandi':
  db.users.find({lastname: 'Nandi'}, {'ssn': 1});

  // retrieve all fields *except* the thumbnail field, for all documents:
  db.users.find({}, {thumbnail:0});
Ebook Download
View all
Learn
View all