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.

square brackets in prehook

See original GitHub issue

Hi, 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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
zbjornsoncommented, Oct 6, 2016

(Based on your indentation and what I understand of your goal, it looks like you’re missing { } for your if 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?

0reactions
vkarpov15commented, Oct 8, 2016

You can just do new Schema({ arr: { type: [String], default: void 0 } }); to avoid the default empty array creation for arr.

Read more comments on GitHub >

github_iconTop 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 >

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