I'm trying to write my own wrapper for the mongojs
collection.find method that should return the collection items selected by the specified query (querying isn't implemented yet, it should simply select all results). The problem is that I'm not getting back an array of results. It seems like the find method does some kind of async callback. So how can I force a synchronous call or force my script to wait?
Collection.prototype.find = function () {
var result = new Array;
if (Bridge.isServer) {
db.collection(name).find(function(err, items) {
items.forEach(function(item) {
result.push(item);
});
});
}
return result;
}