lucid-mongo
lucid-mongo copied to clipboard
Fixed count method: now returns 0 instead of null
The basic usage of the count method does return null instead of 0 (zero) when no document corresponds to the query.
This fix allows developers to use it without encountering unexpected results &/or errors.
Warning: it can lead to breaking changes if developers (who have noticed the behavior) have chosen to test the nullity (e.g.: ==[=] null
) of its return value.
Coverage decreased (-0.08%) to 87.639% when pulling 4a285da73e120270b651e1dd1773dfe8c55b8171 on Pickaw:patch-2 into dd9d100b95992da4c7f95f2906e41115201948dd on duyluonglc:develop.
Coverage decreased (-0.08%) to 87.639% when pulling 4a285da73e120270b651e1dd1773dfe8c55b8171 on Pickaw:patch-2 into dd9d100b95992da4c7f95f2906e41115201948dd on duyluonglc:develop.
That would be a very nice fix to prevent additional/useless conditions! Any plan to merge this PR @duyluonglc? 🙂
Sorry for late response How about the case query count with group by?
const userCount = await User.count('status')
can resolve group by
case and make test script for them?
It seems it's already tested here https://github.com/duyluonglc/lucid-mongo/blob/f42b8901824d61d30caa86e9c749655fdb050fcc/test/unit/lucid.spec.js#L1824-L1827 and here https://github.com/duyluonglc/lucid-mongo/blob/4e4ae36cb4cdefa47a14654c21dd9280f5d5fac7/test/unit/database.spec.js#L160-L161
But, in the case no document matches the query, the returned value is an empty array (in both branches of the merge ; my changes didn't affect the group by count).
If we would want to adapt it consistently, it would imply to make it return an array with a single { _id: null, count: 0}
element.
What do you think about also changing it?
@richie3366 can you make the test script with zero response for both cases?
Do you mean that it also has to return 0
with the group by
query*?
(* in case no document is matched against the query)
@duyluonglc Any update?
Little reminder about my question: I just need to know if you want me to make the groupBy count call to return 0
(thus not a { _id: null, count: 0}
)? (only in the case of no document is matched against the query)
If you need more explanations &/or examples, feel free to ask. Thanks
Hey @duyluonglc, any update about this? Thanks!