question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inserting default values on update/overwrite

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title

Mongoose version

6.6.5

Node.js version

16.17.0

MongoDB version

5.0.6

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.5.1

Issue

Hey there.

I’m currently writing a REST API builder for my application which also uses mongoose.

When implementing PUT, I’m now running into a problem: currently I get the document via findById(), then call overwrite() and markModified() on it and then save(). In these steps, really only those values get written into the document, which are given in overwrite(), while I would expect default values from the defined schema to be set on attributes, which were not given in the PUT request.

Is this just missing, could we add an option for overwrite, is overwrite thought to be “forceful”, do i need the values to be set default mark as changed as well, is there any other option to achieve what I’m currently trying?

Thanks for your help, mongoose really eases a lot of my development.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
vkarpov15commented, Dec 4, 2022

@EtzBetz yes, applyDefaults() only applies defaults on properties whose values are either null or undefined.

0reactions
EtzBetzcommented, Nov 19, 2022

Oh nice, I thought I searched through all the methods, but seems like I didn’t. From my test now, applyDefaults only applies defaults where are a value isn’t set, correct?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does UPDATE overwrite values if they are identical?
No, MySQL won't overwrite identical values. Lets say we insert some data: insert into foo(id,val1,val2,val3) values (0,1,2,3); Query OK, ...
Read more >
Updating Channel Permissions (2020) [Episode #54] - YouTube
In this video we go over how to update channel permissions through a command.
Read more >
Permissions - discord.js Guide
Permissions. Permissions are Discord's primary feature, enabling users to customize their server's workings to their liking.
Read more >
Can you overwrite default values in text boxes?
Solved: Hi, In my form control I have a radio button selector with choices A, B or C. I'm using a switch function...
Read more >
OBJECT_INSERT - Snowflake Documentation
The source object into which the new key-value pair is inserted. ... when set to TRUE, specifies the input value is used to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found