Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. var express = require('express');
  2. var app = express();
  3. var MongoClient = require('mongodb').MongoClient;
  4. var url = "mongodb+srv://Zeroays:<password>@cluster0-hxpge.mongodb.net/test?retryWrites=true&w=majority";
  5. var str = "";
  6.  
  7. app.route('/contacts').get(function(req, res) {
  8. MongoClient.connect(url, function(err, db) {
  9. var dbo = db.db('test');
  10. var collection = dbo.collection('contacts');
  11. var cursor = collection.find({});
  12. console.log(cursor);
  13. str = "";
  14. cursor.forEach(function(item) {
  15. if (item != null) {
  16. str = str + " Name " + item.first_name + "</br>";
  17. }
  18. }, function(err) {
  19. res.send(str);
  20. db.close();
  21. }
  22. );
  23. });
  24. });
  25. var server = app.listen(8080, function() {});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement