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

Cannot $set length field #346

Closed
jidambo opened this issue Apr 7, 2022 · 1 comment
Closed

Cannot $set length field #346

jidambo opened this issue Apr 7, 2022 · 1 comment

Comments

@jidambo
Copy link

jidambo commented Apr 7, 2022

When try to set length field to the document I have N null fields. Tried findOneAndUpdate and update methods.

const setLength = async () => {
  const _id = {your_id};
  const length = 20; // Note: only for number, string works as expected
  
  await db.collection.findOneAndUpdate({_id}, {$set: {length: length}});
}

setLength()

expected result:

db.collection.findOne({_id}) 

{
    _id: {your_id},
    length: 20
}

sad reality:

db.collection.findOne({_id}) 

{
    _id: {your_id},
    "0" : null,
    "1" : null,
    "2" : null,
    "3" : null,
    "4" : null,
    "5" : null,
    "6" : null,
    "7" : null,
    "8" : null,
    "9" : null,
    "10" : null,
    "11" : null,
    "12" : null,
    "13" : null,
    "14" : null,
    "15" : null,
    "16" : null,
    "17" : null,
    "18" : null,
    "19" : null
}
@jidambo
Copy link
Author

jidambo commented Apr 7, 2022

Sorry to bother you. We've added a custom middleware that modifies $set body on update.
Be careful with custom middlewares!

@jidambo jidambo closed this as completed Apr 7, 2022
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

1 participant