[Solved] Very strange: "MongoError: '$set' is empty." when $set is not empty

I’m working on a denormalization/caching package, and I have this code:

console.log('UPDATE:', collection._name)
console.log('SELECTOR:', selector)
console.log('MODIFIER:', modifier)
collection.update(selector, modifier, {multi: true})

When I test it, in console I get this:

I20170828-11:31:32.292(2)? UPDATE: comments
I20170828-11:31:32.292(2)? SELECTOR: { _id: 'comment1' }
I20170828-11:31:32.292(2)? MODIFIER: { '$set': { _post: { _id: 'post1', title: 'My first post' } } }
I20170828-11:31:32.295(2)? Exception in setTimeout callback: MongoError: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}}
I20170828-11:31:32.295(2)?     at Object.Future.wait (/home/simon/.meteor/packages/meteor-tool/.1.5.1.1fuswcw++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:449:15)
I20170828-11:31:32.295(2)?     at [object Object].<anonymous> (packages/meteor.js:209:22)
I20170828-11:31:32.296(2)?     at [object Object].MongoConnection.(anonymous function) [as update] (packages/mongo/mongo_driver.js:778:49)
I20170828-11:31:32.296(2)?     at Object.<anonymous> (packages/matb33_collection-hooks.js:504:27)
I20170828-11:31:32.296(2)?     at Object.collection.(anonymous function) [as update] (packages/matb33_collection-hooks.js:146:21)
I20170828-11:31:32.296(2)?     at [object Object].update (packages/mongo/collection.js:590:29)
I20170828-11:31:32.296(2)?     at [object Object].Mongo.Collection.(anonymous function) [as update] (packages/aldeed_collection2.js:180:19)
I20170828-11:31:32.296(2)?     at packages/herteby:denormalize/denormalize-hooks.js:78:16
I20170828-11:31:32.297(2)?     at /home/simon/KeymasterVue/packages/denormalize/.npm/package/node_modules/lodash/lodash.js:4944:15
I20170828-11:31:32.297(2)?     at baseForOwn (/home/simon/KeymasterVue/packages/denormalize/.npm/package/node_modules/lodash/lodash.js:3001:24)
I20170828-11:31:32.297(2)?     - - - - -
I20170828-11:31:32.297(2)?     at Function.MongoError.create (/home/simon/.meteor/packages/npm-mongo/.2.2.30.1nactzq++os+web.browser+web.cordova/npm/node_modules/mongodb-core/lib/error.js:31:11)
I20170828-11:31:32.297(2)?     at toError (/home/simon/.meteor/packages/npm-mongo/.2.2.30.1nactzq++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/utils.js:139:22)
I20170828-11:31:32.298(2)?     at /home/simon/.meteor/packages/npm-mongo/.2.2.30.1nactzq++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/collection.js:1060:67
I20170828-11:31:32.298(2)?     at /home/simon/.meteor/packages/npm-mongo/.2.2.30.1nactzq++os+web.browser+web.cordova/npm/node_modules/mongodb-core/lib/connection/pool.js:469:18
I20170828-11:31:32.298(2)?     at nextTickCallbackWith0Args (node.js:489:9)
I20170828-11:31:32.298(2)?     at process._tickCallback (node.js:418:13)

How can this be? $set is clearly not empty :disappointed:

Also, the package is working when I use it in my app, I only get this error when testing the package with meteor test-packages packages/denormalize

Here’s the repo

Aha, found the problem. Collection2 was removing the fields without saying anything.

2 Likes