seald/nedb

updating doc record with object name as email address doesnt work

Closed this issue · 14 comments

Describe the bug
when we try to update a doc record when an email address as the object name, its not updating

To Reproduce
will provide example when i create one, im using an existing project of ours so very complex

DOC RECORD FOUND BEFORE UPDATE:

{
    type: 'node',
    _id: 'node/testing123/@W6yMPnkNhZ0r5G3qCWqIrKMikSo4b$Zj7jcxCke8MScHzKLvnJXdk24FZHsusV3',
    meshid: 'mesh/testing123/gNiuiLhuYvmFngWf$gdwwQdLBVRvEfhE9sijCPxw9nh12GRevyiEoLp9QBRBRow7',
    mtype: 3,
    icon: 1,
    name: '192.168.168.123',
    host: '192.168.168.123',
    domain: 'testing123',
    agent: { id: 6, caps: 0 }
}

DOC RECORD WHAT I WANT TO BE UPDATED

{
  type: 'node',
  _id: 'node/testing123/@W6yMPnkNhZ0r5G3qCWqIrKMikSo4b$Zj7jcxCke8MScHzKLvnJXdk24FZHsusV3',
  meshid: 'mesh/testing123/gNiuiLhuYvmFngWf$gdwwQdLBVRvEfhE9sijCPxw9nh12GRevyiEoLp9QBRBRow7',
  mtype: 3,
  icon: 1,
  name: '192.168.168.123',
  host: '192.168.168.123',
  domain: 'testing123',
  agent: { id: 6, caps: 0 },
  ssh: { 'user/testing123/simon@testing123.com': { u: 'root', p: 'mypass' } }
}

Expected behavior
for the record to be updated

Actual behavior
record isnt updated

Logs
Any log you can provide that showcases the problem.

Environment info

  • Runtime: [e.g Node, browser (if so which one), React-native (if so, is Hermes enabled or not)] Node
  • Version: [e.g. v12.1, v95, v0.66.1] 18/20
  • OS: [e.g. macOS 12.0.1, iOS 11, Windows 11 build xxxx] Windows/Linux
  • Device (if applicable): [e.g. iPhone X, MacBookPro14,1]

Additional context
we use to use https://github.com/louischatriot/nedb
then moved to https://github.com/yetzt/forked-nedb
now moving again to https://github.com/seald/nedb

Hi @si458 ,

I'm sorry I don't understand exactly your issue, are you saying that when you update a document's field with an email address, it fails silently?

yes sorry for explaining it badly i tried my best,
the doc on top is whats in the database when i search for it,
the doc underneath it is what i then update it with (so ive added the ssh line to the doc)
but for some reason it never actually updates the doc record?
it appears the object name user/testing123/simon@testing123.com doesnt like the @ symbol?
im trying to work out how to get it to output logs etc for me to debug it

edit:
our update command is this
obj.file.update({ _id: xdata._id }, xdata, { upsert: true }, func);
xdata is the 2nd doc record on top with the ssh line added

right i forgot to add a func to out call and turns out nedb doesnt like full stops! fuck...

Error: Field names cannot contain a .
    at checkKey (/home/simon/meshcentral/MeshCentral/node_modules/@seald-io/nedb/lib/model.js:31:36)
    at checkObject (/home/simon/meshcentral/MeshCentral/node_modules/@seald-io/nedb/lib/model.js:50:9)
    at checkObject (/home/simon/meshcentral/MeshCentral/node_modules/@seald-io/nedb/lib/model.js:51:9)
    at Object.modify (/home/simon/meshcentral/MeshCentral/node_modules/@seald-io/nedb/lib/model.js:470:3)
    at Datastore._updateAsync (/home/simon/meshcentral/MeshCentral/node_modules/@seald-io/nedb/lib/datastore.js:991:29)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) undefined undefined undefined

I think it is because of the dot . more than the @

@tex0l yeh refer to #55 (comment)
any suggestions as we MUST have full stops?

The obvious workaround is to encode the email address in base64

thats a HUGE database change tho, oh poo, as we use the format of FUNC/SERVER/EMAIL
ill have to think what we can do, thanks anyways

I'm sorry about that, this is a breaking change we've introduced due to #27

Actually no, it is not a breaking change! The initial nedb implementation already has this limitation

What #27 introduced is the impossibility to use commas

the issue existed in the original nedb project, and also a forked version,
we just decided to move again to your repo as you had loads of fixes etc

thanks for your help tho @tex0l !

@tex0l if i remove the line below, my app works, no issues so far!

if (k.indexOf('.') !== -1) throw new Error('Field names cannot contain a .')

any chance you could add an option to IGNORE full stops, when i initialise a database?
this would allow us to move to your repo/version and also upgrade to async properly!

Unfortunately no as nedb uses the dot notation for referencing deep keys in objects, please read this section of the documentation: https://github.com/seald/nedb?tab=readme-ov-file#basic-querying

thanks @tex0l i just discovered this before, we do use deepkeys for stuff,
thanks again for your help,
we will defo think about switching to this repo as the is loads more bug fixes and just seems quicker for some reason?