
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var ObjectId = require('mongodb').ObjectID;
var url = 'mongodb://localhost:27017/test';

var express = require("express");
var app     = express();
var path    = require("path");

app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/'));

app.get('/',function(req,res){
  var randomID;
  MongoClient.connect(url, function(err, db) {
    assert.equal(null, err);
    db.collection('videos', function(err, coll) {
       coll.count(function(err, result){
        db.collection('youtubes').findOne({_id: Math.floor(Math.random() * (result-1)) + 1}, function(err, document) {
          console.log(document);
          randomID = document["Video UR"];
          console.log(randomID);
          db.close();
          res.render(path.join(__dirname+'/index'), { videoID: randomID});
        });
      });
    });
  });
});

app.listen(3000);

@@ -571,15 +571,13 @@
 on('
-youtube
+video
 s').
@@ -657,24 +657,55 @@
 document) %7B%0A
+          console.log(result);%0A
           co
@@ -823,16 +823,16 @@
 lose();%0A
-
         
@@ -935,24 +935,540 @@
 %0A  %7D);%0A%7D);%0A%0A
+app.get('/api/getvid',function(req,res)%7B%0A  var randomID;%0A  MongoClient.connect(url, function(err, db) %7B%0A    assert.equal(null, err);%0A    db.collection('videos', function(err, coll) %7B%0A       coll.count(function(err, result)%7B%0A        db.collection('videos').findOne(%7B_id: Math.floor(Math.random() * (result-1)) + 1%7D, function(err, document) %7B%0A          randomID = document%5B%22Video UR%22%5D;%0A          console.log(randomID);%0A          db.close();%0A          res.json(%7Bid: randomID%7D);%0A        %7D);%0A      %7D);%0A    %7D);%0A  %7D);%0A%7D);%0A%0A
 app.listen(3

Create backend autoplay API