WiserSolutions/quadro

MongoError on calling Model.save()

KiChjang opened this issue · 0 comments

Brief issue description

MongoError is thrown when calling Model.save() on a model instance that has only mutated a non-attribute field.

Test case example (desirable)

Q.Model('session', {
  attributes: {
    sid: 'string',
    proxy: 'string',
    createdAt: 'date'
  }
})

it('does not save isExistingSession to database', async function() {
  let session1 = await Session.create({ sid })
  session1.isExistingSession = true
  await session1.save()
  let session2 = await Session.get({ sid })
  expect(session2.isExistingSession).to.be.undefined
})

Expected outcome

Should not throw MongoError, and session2.isExistingSession should not exist.

Actual outcome

MongoError is thrown:

    MongoError: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}}
      at Function.MongoError.create (node_modules/quadro/node_modules/mongodb-core/lib/error.js:31:11)
      at toError (node_modules/quadro/node_modules/mongodb/lib/utils.js:139:22)
      at node_modules/quadro/node_modules/mongodb/lib/collection.js:1060:67
      at node_modules/quadro/node_modules/mongodb-core/lib/connection/pool.js:469:18
      at _combinedTickCallback (internal/process/next_tick.js:131:7)
      at process._tickDomainCallback (internal/process/next_tick.js:218:9)