-1

I have records like these:

{
  "_id": {
    "$oid": "60a50118a9aa9deb2cbbbd0b"
  },
  "userId": "id10",
  "crmId": "HG3F5BG89"
}

How can I select specified field? For example I want to select records by userId = "id10" and then return only crmId field value?

Operation: findOne

  • 1
    refer document [findOne()](https://docs.mongodb.com/manual/reference/method/db.collection.findOne/) and see similar question [How to select a single field for all documents in a MongoDB collection?](https://stackoverflow.com/questions/25589113/how-to-select-a-single-field-for-all-documents-in-a-mongodb-collection) – turivishal Jun 02 '21 at 15:05

1 Answers1

1

This will work in mongo shell: db.collectionName.findOne({userId: "id10"}, {_id: 0, crmId: 1});

Replace collectionName with the name of your collection.

Charchit Kapoor
  • 8,934
  • 2
  • 8
  • 24