# Hook afterInsert behavior very inconsistent.

**URL:** <https://forum.wixstudio.com/t/hook-afterinsert-behavior-very-inconsistent/20524>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 9, 2019, 12:32pm UTC](https://forum.wixstudio.com/t/hook-afterinsert-behavior-very-inconsistent/20524 "2019-05-09T12:32:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![christianeasterly](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/christianeasterly/32/5933_2.png) [@christianeasterly](https://forum.wixstudio.com/u/christianeasterly)\
**Post date:** [May 9, 2019, 12:32pm UTC](https://forum.wixstudio.com/t/hook-afterinsert-behavior-very-inconsistent/20524/1 "2019-05-09T12:32:57Z")

</div>

Was wondering if anyone could possibly tell me a work around for this not counting properly.

About 4 out of 5 times, this data query inside my hook returns the correct value. But sometimes it appears to not be counting the additional entry that set the hook off itself. About 1 out of 5 times it counts one less than the actual number of results it should be finding. Should I not be using a query in a hook? It seems like sometimes the hook is starting before the owner field is finished being filled in on the inserted item or something. Is there a better way to handle a count inside of a hook? There are no errors, it always gives me a count, it’s just not always right (if I get the wrong count, it’s always 1 less than it should have been)

export function UserSubmitsLand\_afterInsert(item, context) {  
**let** hookContext = context;  
**let** memberEntry = item.\_owner  
**var** submitted  
wixData.query(“UserSubmitsLand”).eq(“\_owner”, memberEntry).count()  
.then((num) =\> {  
console.log(“initial query found " + num + " results”);  
…(rest of script which works fine)

---

<div class="post-metadata">

**Author:** ![christianeasterly](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/christianeasterly/32/5933_2.png) [@christianeasterly](https://forum.wixstudio.com/u/christianeasterly)\
**Post date:** [May 9, 2019, 5:41pm UTC](https://forum.wixstudio.com/t/hook-afterinsert-behavior-very-inconsistent/20524/2 "2019-05-09T17:41:01Z")

</div>

I am able to reproduce this by adding an item both through the site / dataset, or manually from the collection. It happens more often when I’m using mobile for some reason.
