Guest User

Untitled

a guest
Dec 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. const mongodb = require("mongodb");
  2.  
  3. run().catch(error => console.error(error));
  4.  
  5. async function run() {
  6. console.log(new Date(), "Connecting to localhost");
  7. const uri = "mongodb://127.0.0.1:27017/test?replicaSet=repl0";
  8. const client = await mongodb.MongoClient.connect(
  9. uri,
  10. function(err, client) {
  11. if (err) throw err;
  12. const db = client.db("IoTData");
  13. const Filter = [
  14. {
  15. $match: {
  16. operationType: { $in: ["insert"] },
  17. "fullDocument.cameraImage": { $exists: true }
  18. }
  19. }
  20. ];
  21.  
  22. console.log(new Date(), "Watching for changes...");
  23. db.collection("SecurityApp")
  24. .watch(Filter)
  25. .on("change", data => {
  26. console.log(new Date(), "Camera Image Attached to Document!");
  27. });
  28. }
  29. );
  30. }
  31. /* Make sure you are using at least MongoDB NodeJS Driver 3.0 and above
  32. {
  33. "name": "detectnewfield",
  34. "version": "1.0.0",
  35. "description": "Detects New Field",
  36. "main": "DetectHighTemp.js",
  37. "scripts": {
  38. "debug": "node DetectNewField.js"
  39. },
  40. "author": "Rob Walters",
  41. "license": "MIT",
  42. "dependencies": {
  43. "mongodb": "^3.1.0"
  44. }
  45. }*/
Add Comment
Please, Sign In to add comment