1

My current document structure looks like this:

{'_id': ObjectId('5rdfgd63sdg'),
 'car': '1.16958',
 'bike': '1.16968',
 'van': '1.16951',
 'sedan': '1.16954',
 'volume': 25}

I have 500 documents like this in a single collection. I would like to query all values from 'bike' for example.

The SQL equivalent of what I'd like is SELECT bike from db.name

dataviews
  • 2,466
  • 7
  • 31
  • 64
  • Possible duplicate of [How to select a single field in MongoDB?](https://stackoverflow.com/questions/25589113/how-to-select-a-single-field-in-mongodb) – Ashh Sep 18 '18 at 12:32
  • Possible duplicate of [MONGO get only the name of documents but not the whole documents](https://stackoverflow.com/questions/52212165/mongo-get-only-the-name-of-documents-but-not-the-whole-documents/52212258#52212258) – Ashh Sep 18 '18 at 12:35
  • @AnthonyWinzlet thank you – dataviews Sep 18 '18 at 12:38

2 Answers2

1
db.collection('collectionName')
  .find({})
  .project({ bike: 1 });
Rahul kumar
  • 44
  • 1
  • 9
0

I was able to use a loop:

for x in collection.find({}, {"volume": "true"}):
    print(x)
dataviews
  • 2,466
  • 7
  • 31
  • 64