Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express');
  2. var router = express.Router();
  3.  
  4. /* GET home page. */
  5. router.get('/', function(req, res, next) {
  6.  
  7.   res.render('index', { title: 'Express' });
  8. });
  9.  
  10.  
  11. var mongodb = require('mongodb');
  12.  
  13. //We need to work with "MongoClient" interface in order to connect to a mongodb server.
  14. var MongoClient = mongodb.MongoClient;
  15.  
  16. // Connection URL. This is where your mongodb server is running.
  17. var url = 'mongodb://localhost:27017/rgdata';
  18.  
  19. // Use connect method to connect to the Server
  20. MongoClient.connect(url, function (err, db) {
  21.   if (err) {
  22.     console.log('Unable to connect to the mongoDB server. Error:', err);
  23.   } else {
  24.     //HURRAY!! We are connected. :)
  25.     console.log('Connection established to', url);
  26.  
  27.     // do some work here with the database.
  28.  
  29.    var collection = db.collection('rglist2');
  30.  
  31.  
  32.    //if(collection.find({_field2: 'Omsk State Pedagogical University'}))
  33.     //console.log('Founded');
  34.  
  35.  
  36.   collection.find({_field2: 'Omsk State Pedagogical University'}).toArray(function (err, result) {
  37.       if (err) {
  38.         console.log(err);
  39.       } else if (result.length) {
  40.         console.log('Found:', result);
  41.       } else {
  42.         console.log('No document(s) found with defined "find" criteria!');
  43.       }
  44.  
  45.  
  46.  
  47.     //Close connection
  48.     db.close();
  49.   }
  50. });
  51.  
  52.  
  53. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement