Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongodb = require("mongodb");
- run().catch(error => console.error(error));
- async function run() {
- console.log(new Date(), "Connecting to localhost");
- const uri = "mongodb://127.0.0.1:27017/test?replicaSet=repl0";
- const client = await mongodb.MongoClient.connect(
- uri,
- function(err, client) {
- if (err) throw err;
- const db = client.db("IoTData");
- const Filter = [
- {
- $match: {
- operationType: { $in: ["insert"] },
- "fullDocument.cameraImage": { $exists: true }
- }
- }
- ];
- console.log(new Date(), "Watching for changes...");
- db.collection("SecurityApp")
- .watch(Filter)
- .on("change", data => {
- console.log(new Date(), "Camera Image Attached to Document!");
- });
- }
- );
- }
- /* Make sure you are using at least MongoDB NodeJS Driver 3.0 and above
- {
- "name": "detectnewfield",
- "version": "1.0.0",
- "description": "Detects New Field",
- "main": "DetectHighTemp.js",
- "scripts": {
- "debug": "node DetectNewField.js"
- },
- "author": "Rob Walters",
- "license": "MIT",
- "dependencies": {
- "mongodb": "^3.1.0"
- }
- }*/
Add Comment
Please, Sign In to add comment