Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating doc record with object name as email address doesnt work #55

Closed
si458 opened this issue Mar 1, 2024 · 14 comments
Closed

updating doc record with object name as email address doesnt work #55

si458 opened this issue Mar 1, 2024 · 14 comments

Comments

@si458
Copy link

si458 commented Mar 1, 2024

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

@tex0l
Copy link

tex0l commented Mar 1, 2024

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?

@si458
Copy link
Author

si458 commented Mar 1, 2024

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

@si458
Copy link
Author

si458 commented Mar 1, 2024

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

@tex0l
Copy link

tex0l commented Mar 1, 2024

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

@si458
Copy link
Author

si458 commented Mar 1, 2024

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

@tex0l
Copy link

tex0l commented Mar 1, 2024

The obvious workaround is to encode the email address in base64

@si458
Copy link
Author

si458 commented Mar 1, 2024

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

@si458 si458 closed this as completed Mar 1, 2024
@tex0l
Copy link

tex0l commented Mar 1, 2024

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

@tex0l
Copy link

tex0l commented Mar 1, 2024

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

@si458
Copy link
Author

si458 commented Mar 1, 2024

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

@si458
Copy link
Author

si458 commented Mar 1, 2024

thanks for your help tho @tex0l !

@si458
Copy link
Author

si458 commented Mar 1, 2024

@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!

@tex0l
Copy link

tex0l commented Mar 1, 2024

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

@si458
Copy link
Author

si458 commented Mar 1, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants