// connect to relicationSet odroid01
const db = connect("mongodb://siteRootAdmin:b23258585@x8664Arch.yushei.com.tw:27017,hc4Jammy.yushei.com.tw:27017,n2Jammy.yushei.com.tw:27017/YuSheiDBTest?replicaSet=odroid01&authSource=admin");
// let log = rs.status().members;
// console.table(log);
function alert() {
let log = rs.status().members;
let simpleLog = [];
// console.log(log);
for (let i = 0; i < log.length; i++){
// console.log("_id: ", log[i]._id, "name: ", log[i].name, "health: ", log[i].health, "state: ", log[i].state, "stateStr: ", log[i].stateStr);
simpleLog[i] = {
"_id": log[i]._id,
"name": log[i].name,
"health": log[i].health,
"state": log[i].state,
"stateStr": log[i].stateStr
}
}
console.table(simpleLog);
console.log(Date().toLocaleString());
}
alert();
// Connect to the MongoDB server and select your database
// const conn = new Mongo();
// const db = conn.getDB('your_database_name');
// Replace 'your_capped_collection_name' with the name of your capped collection
const collection = db.getCollection('inLaneCapped');
// Watch the capped collection for changes
const changeStream = collection.watch();
// Function to process each change and print specific fields
const processChange = (change) => {
if (change.operationType === 'insert') {
// _id: , plateText: 'NEF6953', cameraSource: '002', inTime: '2023-07-25T17:17:04', inCarJpg
const { _id, plateText, cameraSource, inTime, inCarJpg } = change.fullDocument; // Add the specific fields you want to print
// Create a simple textual representation of the image
// const imageText = 'Image data: ' + inCarJpg.slice(0, 50) + '...'; // Display only a portion of the base64 data
// const imageLink = `data:image/jpeg;base64,${inCarJpg}`;
print(`Change ID: ${_id}`);
print(`plateText: ${plateText}`);
print(`camerSource: ${cameraSource}`);
print(`inTime: ${inTime}`);
// print(`inCarJpg: ${imageText}`);
// print(`Image Link: ${imageLink}`);
//print(`inCarJpg: <img src="${inCarJpg}" alt="Car Image" />`);
}
};
// Start the change stream and monitor for changes
const monitorChanges = async () => {
while (true) {
const change = await changeStream.tryNext();
if (change) {
processChange(change);
} else {
// Sleep for a short interval before checking again
sleep(100);
}
}
};
monitorChanges().catch(printjson); // Start monitoring changes
The above is the code I am runnning on a terminal. Please change to a web site, and put the above code in it.
Return to Top