Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. var MongoClient = require('mongodb').MongoClient;
  2. var assert = require('assert');
  3. var ObjectId = require('mongodb').ObjectID;
  4. var url = 'mongodb://localhost:27017/test';
  5.  
  6. var findRestaurants = function(db, callback) {
  7. var cursor =db.collection('restaurants').find( );
  8. cursor.each(function(err, doc) {
  9. assert.equal(err, null);
  10. if (doc != null) {
  11. console.dir(doc);
  12. } else {
  13. callback();
  14. }
  15. });
  16. };
  17. // Connect to the db
  18. MongoClient.connect(url, function(err, db) {
  19. assert.equal(null, err);
  20. findRestaurants(db, function() { //I don't want to do this as soon as the server starts
  21. db.close();
  22. });
  23. });
  24.  
  25. //if I put findRestaurant here,
  26. function findRestaurant(data){
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement