Skip to content

Instantly share code, notes, and snippets.

@RWaltersMA
Created December 17, 2018 12:50
Show Gist options
  • Save RWaltersMA/c312cb9be0ef5a699ec82bf373b672ad to your computer and use it in GitHub Desktop.
Save RWaltersMA/c312cb9be0ef5a699ec82bf373b672ad to your computer and use it in GitHub Desktop.
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"
}
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment