Revisions for "MongoDB (Node.JS) Create, Append, and Update."

MongoDB Node.js Make $addToSet ignore a key, avoid duplicates

var database = async (parameter, component) => {
let timestamp = new Date().getTime()
await row.findOneAndUpdate({ _id: parameter.relative }, { $addToSet: { cluster: { url: parameter.absolute, component: component, firstSeen: timestamp, lastSeen: timestamp } }, $set: { _id: parameter.relative } }, { upsert: !0 });
}

Update array "cluster": Add unchangeable "first seen" timestamp, add updatable "last seen" timestamp, update "component" if required; Without creating duplicates!

How could I force MongoDB to ignore the "firstSeeen" key and update the "lastSeen" + "component" key without creating a new array?

Is there something that could force $addToSet to ignore different keys?

MongoDB (Node.JS) CRUD Operations
`var function database = async (parameter(param_01, component) => { letparam_02) { object = { _id: param_01, array: [ [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], ] } } Desired timestamp = newResult Date().getTime() awaitin row.findOneAndUpdate({ _id: parameter.relative }, { $addToSet: { cluster: { url: parameter.absolute, component: component, firstSeen: timestamp, lastSeen: timestamp } }, $set: { _id: parameter.relative } }, { upsert: !0 }); } ` Update array "cluster": Add unchangeable "first seen" timestamp, add updatable "last seen" timestamp, update "component" if required; Without creating duplicates! How could I force MongoDB, allow 'lastSeen' to tobe ignoreupdated the "firstSeeen" key and update the "lastSeen" + "component" key without creating a newduplicate array? Is there something that could force $addToSet to ignore different keys?: object = { _id: "example", array: [ ["hello", 3910, 4930], ["world", 3913, 2344], ["happy", 3133, 3340], ["cloud", 3930, 1139], ] }
MongoDB (Node.JS) CRUD Operations
function database(param_01, param_02) { object = { _id: param_01, array: [ [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], ] } } Desired Result in MongoDB, allow 'lastSeen' to be updated without creating a duplicate array: (upsert required): object = { _id: "example", array: [ ["hello", 3910, 4930], ["world", 3913, 2344], ["happy", 3133, 3340], ["cloud", 3930, 1139], ] }
MongoDB (Node.JS) Create, Append, and Update.
functionI database(param_01, param_02) { object = { _id: param_01, array: [ [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], [param_02, firstSeen, lastSeen], ] } } Desiredam Resultlooking to achieve the following operations with the MongoDB Node.JS driver, could this be performed with an optimal approach? There are three possible operations required: create, append, and update. Create the following document: { "_id": "hello_world_cluster", "items": [ { "item_name": "my_item_one", "first_seen": 1000, "last_seen": 1000, "logic": true } ] } Append new items to an array: { "_id": "hello_world_cluster", "array": [ { "item_name": "my_item_one", "first_seen": 1000, "last_seen": 1000, "logic": true }, { "item_name": "my_item_two", "first_seen": 2000, "last_seen": 2000, "logic": true }, { "item_name": "my_item_three", "first_seen": 3000, "last_seen": 3000, "logic": true } ] } Update items that are found in MongoDB, allow 'lastSeen' toan be updated without creating a duplicate array (upsert required): object = { : { "_id: "example", array: [ ["hello", 3910, 4930], ["world", 3913, 2344], ["happy", 3133, 3340], ["cloud", 3930, 1139], ] }": "hello_world_cluster", "items": [ { "item_name": "my_item_one", "first_seen": 1000, "last_seen": 4000, "logic": false }, { "item_name": "my_item_two", "first_seen": 2000, "last_seen": 2000, "logic": true }, { "item_name": "my_item_three", "first_seen": 3000, "last_seen": 3000, "logic": true } ] }
Back to question