I'm calling a mongodb query and need to assign the result to a value.
function oneref(db, coll, cb) {
var pipeline = [{ "$sample": { size: 1 } }]
var ohoh
coll.aggregate(pipeline, function (err,oneref) {
ohoh=oneref[0].code
})
console.log('hoho?: ' + ohoh)
cb(null, db, coll)
},
I understand I have an issue understanding callback, but even checking all hello world examples, I'm struggling.
How to write it in the simplest way so I only assigne the var hoho when the query finished?
Thanks a lot in advance.