mongoskin select special fields rather than all

494 views Asked by At

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

1

There are 1 answers

0
Aditya On BEST ANSWER

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.