Perhaps my PHP brain does not allow me to do nodejs all I want function "myfindindb" to return a value, is that possible with nodejs? I am aware of async, is this the reason for not working like a waterfall?
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var ObjectId = require('mongodb').ObjectID;
var url = 'mongodb://localhost:27017/exampleDb';
var mysite = '';
var myisfound;
var numItems = '';
function myfindindb(mysite) {
var findRestaurants = function(db, callback) {
var cursor = db.collection('restaurants').find({
"site": mysite
}).limit(1);
cursor.each(function(err, doc) {
assert.equal(err, null);
var myresults = doc.site;
return callback(myresults);
});
};
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
findRestaurants(db, function(myresults,callback) {
console.dir(myresults); //as far as Iv got goo so far
db.close();
return callback(myresults); //this bit wont work??
});
});
}
var foo = myfindindb('http://google.com');
console.log(foo);