oizryx
oizryx

Reputation: 1

I'm working with mongoose and nodejs, but not able to print what i want to

let somevar = candidate.find({}, {_id:0,name:1 });
console.log(somevar.map());

Current output which was not expected

Query {
...
    collectionName: 'candidates'
  },
  _traceFunction: undefined,
  '$useProjection': true,
  _userProvidedFields: { _id: 0, name: 1 }       
}

Im not able to understand the error, so want someone to explain me whats happening here. What i expected it to do is

["name1","name2".....]

Upvotes: 0

Views: 25

Answers (1)

iagowp
iagowp

Reputation: 2494

You are creating a query but not executing it. You need to either do:

let someVar = await candidate.find()

Or

candidate.find().exec(function(err, candidates){
  console.log(candidates)
});

Upvotes: 2

Related Questions