2

I'm looking for a way to get special fields from mongoskin find function. in other words in SQL lang we say select column1,column2,column3 from mytable rather than select *

currently my query is like below and i want to get specify the fields that I'm looking for rather the the whole json object.

db.collection('collacta').find().toArray(function(err, result) {
            if (result) {
                ...
            } else {
                ...
            };
        });

thanks

max imax
  • 2,131
  • 3
  • 15
  • 16

1 Answers1

2

For getting the projection of fields, you should pass the DBObject for projection,

DBCursor cursor = collection.find(query, projectionQuery);

The projection is The DBObject in form of key-value pair. where,

key is the name of field you want to project. value can be either 0 or 1.
0 - means exclude the particular column from result set.
1 - means include the particular column in result set.

For more info, see here.

Aditya
  • 1,334
  • 1
  • 12
  • 23