Browse Source

tweak change-stream to include updates

master
Rich Brown 8 months ago
parent
commit
8a4ffc2d8c
2 changed files with 16 additions and 6 deletions
  1. +8
    -4
      index.html
  2. +8
    -2
      index.js

+ 8
- 4
index.html View File

@@ -66,10 +66,14 @@
};
const socket = io.connect("/");
socket.on("color", data => {
const { color, username } = data;
colorDiv.style["background-color"] = color;
usernameP.innerHTML = username;
usernameP.style.color = invertHex(color);
if (data.color && data.username) {
const { color, username } = data;
colorDiv.style["background-color"] = color;
usernameP.innerHTML = username;
usernameP.style.color = invertHex(color);
} else {
console.log("socket-color was triggered but no data delivered");
}
});
</script>
</body>


+ 8
- 2
index.js View File

@@ -36,8 +36,14 @@ io.on("connection", socket => {
client.connect(function(err, database) {
assert.equal(null, err);
const db = database.db(databaseName);
const stream = db.collection("entries").watch();
stream.on("change", ({ fullDocument }) => emitter(fullDocument));
const stream = db
.collection("entries")
.watch({ fullDocument: "updateLookup" }); // ensures updates contain fullDocument, not just *new* entries
stream.on("change", data => {
if (data.fullDocument) {
emitter(data.fullDocument);
}
});

// temp
// make test users


Loading…
Cancel
Save