Where col is the connection to my database. However, when I run this code I get an error that ‘$set’ is empty, even though it’s the correct type (object) and is truthy. What am I missing?
MongoError: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}}
at Function.create (/home/runner/gli-forktery-1/node_modules/mongodb/lib/core/error.js:57:12)
at toError (/home/runner/gli-forktery-1/node_modules/mongodb/lib/utils.js:123:22)
at /home/runner/gli-forktery-1/node_modules/mongodb/lib/operations/common_functions.js:379:39
at handler (/home/runner/gli-forktery-1/node_modules/mongodb/lib/core/sdam/topology.js:942:24)
at /home/runner/gli-forktery-1/node_modules/mongodb/lib/cmap/connection_pool.js:350:13
at handleOperationResult (/home/runner/gli-forktery-1/node_modules/mongodb/lib/core/sdam/server.js:558:5)
at MessageStream.messageHandler (/home/runner/gli-forktery-1/node_modules/mongodb/lib/cmap/connection.js:277:5)
at MessageStream.emit (events.js:315:20)
at processIncomingData (/home/runner/gli-forktery-1/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/home/runner/gli-forktery-1/node_modules/mongodb/lib/cmap/message_stream.js:42:5) {
driver: true,
index: 0,
code: 9
Interestingly enough the error seems to originate from MongoDB itself, not my code: .../mongodb/lib/core/error.js:57:12
Update:
So, turns out part of the error was brackets:
Did you mean to use Date.now() with parentheses? I think maybe mongo would have stripped out the field date: Date.now because the value was a function.
I actually tried that exact code (col.updateMany({}, update)), but it threw that “$set is empty” error.
I should probably backtrack and do some testing with update just to get familiar with it again.
Date.now was passed successfully into the database. I suspect update is a reserved word in Javascript? In any case, I’ll work this into my dev repo right now.