Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var MongoClient = require('mongodb').MongoClient;
- var url = "mongodb+srv://Zeroays:<password>@cluster0-hxpge.mongodb.net/test?retryWrites=true&w=majority";
- var str = "";
- app.route('/contacts').get(function(req, res) {
- MongoClient.connect(url, function(err, db) {
- var dbo = db.db('test');
- var collection = dbo.collection('contacts');
- var cursor = collection.find({});
- console.log(cursor);
- str = "";
- cursor.forEach(function(item) {
- if (item != null) {
- str = str + " Name " + item.first_name + "</br>";
- }
- }, function(err) {
- res.send(str);
- db.close();
- }
- );
- });
- });
- var server = app.listen(8080, function() {});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement