0

I'm working on a nodejs + express + mongodb project. I'm using monk for accessing my mongo DB.

var myvar;
var myCollection = db.get('myCollection');
myCollection.find({},function(e,docs){
myvar = docs;
})
console.log(myvar)

This outputs undefined. If I try to output the object inside the function, there is no problem. How can I save the object globally?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tom Broucke
  • 249
  • 2
  • 13

0 Answers0