Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var router = express.Router();
- /* GET home page. */
- router.get('/', function(req, res, next) {
- res.render('index', { title: 'Express' });
- });
- var mongodb = require('mongodb');
- //We need to work with "MongoClient" interface in order to connect to a mongodb server.
- var MongoClient = mongodb.MongoClient;
- // Connection URL. This is where your mongodb server is running.
- var url = 'mongodb://localhost:27017/rgdata';
- // Use connect method to connect to the Server
- MongoClient.connect(url, function (err, db) {
- if (err) {
- console.log('Unable to connect to the mongoDB server. Error:', err);
- } else {
- //HURRAY!! We are connected. :)
- console.log('Connection established to', url);
- // do some work here with the database.
- var collection = db.collection('rglist2');
- //if(collection.find({_field2: 'Omsk State Pedagogical University'}))
- //console.log('Founded');
- collection.find({_field1: 'Omsk State Pedagogical University'}).toArray(function (err, result)
- {
- if (err)
- {
- console.log(err);
- } else if (result.length)
- {
- console.log('Found:', result);
- } else
- {
- console.log('No document(s) found with defined "find" criteria!');
- }
- //Close connection
- db.close();
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement