square brackets in prehook
See original GitHub issueHi, I want to avoid mongoose empty array creation.
mySchema.pre('save', function (next) { [ "item1", "item2", "item3", "item4" ].forEach(function (field) { if (this[field] && isEmpty (this[field])) this[field] = undefined; }); next(); })
I cannot access to the fields using square brackets, how can I generalize this behaviour for multiple items?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
pre-hook & post-hook - dbt Developer Hub
dbt aims to provide all the boilerplate SQL you need (DDL, DML, and DCL) via out-of-the-box functionality, which you can configure quickly and ......
Read more >Empty Square Brackets in Javascript? - reactjs - Stack Overflow
It's an array of dependencies. If one of them changes, the "current" effect will be cancelled/cleaned up and the effect function will be ......
Read more >Solved: Bitbucker prehook configurations - Atlassian Community
Solved: I am using Windows system. I am configuring Bit-bucket precommit hooks, Use case is "I want to reject all the commits that...
Read more >Square Brackets - Brackets Corners Hooks - Browse Hardware
Square Brackets ; Shelf Support · 283SB2 Shelf Support. $10.68 ; Shelf Support · 283SB1 Shelf Support. $6.11 ; 8" Bracket Pair ·...
Read more >How is it possible to use square brackets as shorthand ...
What you asked for can be done with LaTeX3's regex module: \documentclass{article} \usepackage{xcolor} \usepackage{xparse} ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
(Based on your indentation and what I understand of your goal, it looks like you’re missing
{
}
for yourif
block.)Looking at the source around that trace, it looks like the replaced value needs to be falsy in order for mongoose to not attempt to emit an event. Does it still fail with
undefined
?You can just do
new Schema({ arr: { type: [String], default: void 0 } });
to avoid the default empty array creation forarr
.