Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
74
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({_field1: 'Omsk State Pedagogical University'}).toArray(function (err, result)
  37.   {
  38.       if (err)
  39.       {
  40.         console.log(err);
  41.       } else if (result.length)
  42.       {
  43.         console.log('Found:', result);
  44.       } else
  45.       {
  46.         console.log('No document(s) found with defined "find" criteria!');
  47.       }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.     //Close connection
  54.     db.close();
  55.  
  56. });
  57.  
  58.  
  59. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement