Meteor-Community-Packages / Meteor-Community-Packages/meteor-collection-hooks

`$pull` calls .update hook twice, once with null, once as it should be

Open
#175 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
656
Forks
94
Avg merge
3d 4h
Merged PRs (30d)
2

Description

Hello,

First, thanks for a great plugin!

Now to the problem: When I run a `$pull` command in mongodb, a strange thing happens. It calls my .update collection hook twice. The first time, with a `null` in place of the object, and the second time with the `null` removed.

First time

```
//this.previous
{
_id:"dsflaklfjslj",
myArr:[{_id:aeeoeio",val:"23"}]
}
//doc
{
_id:"dsflaklfjslj",
myArr:[null]
}
```

Now second time it is called

```
//this.previous
{
_id:"dsflaklfjslj",
myArr:[null]
}
//doc
{
_id:"dsflaklfjslj",
myArr:[]
}
```

This looks like a bug - it should only be called once with the null removed.

Thanks!

Contributor guide

Open the contributing guide

Research direction

The issue names MongoDB's $pull operation and the collection update hook but no source file or test. Start by reproducing a $pull that removes an array element and trace the hook calls and intermediate documents. Done means the update hook runs once, with the removed element absent and no null intermediate state.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.