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.

Suggestion: `$count` special query param? Where it literally just returns the number in place of `hook.result`.

See original GitHub issue

What do you guys think about a $count special query param? Where it literally just returns the number in place of hook.result. The reason I ask is knowing to set $limit: 0 is a bit esoteric and feels like a hack. Plus with the new populate hook if you wanted to just get a count of the related items you can do

function(hook) {
  if(hook.params.query.$count) {
    hook.params.query.$limit = 0;
    delete hook.params.query.$count;
  }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hubgitcommented, Mar 16, 2017

@eddyystop I’m actually trying to get the count of nested objects within a populate hook, like this:

hooks.populate({
  schema: {
    include: [
      {
        service: 'comments',
        nameAs: 'comments_count',
        parentField: 'id',
        childField: 'post_id',
        query: {
          $count: true, // this would be nice
        },
      }
    ]
  }
})
0reactions
oussamaABIDcommented, May 18, 2018

what about total of find

app.service().find({// query to count})
//count  == result.total 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks - Apollo GraphQL Docs
A GraphQL query string parsed into an AST with the gql template literal. Optional for the useQuery hook, because the query can be...
Read more >
Adding filters based on the query - Algolia
Using the dashboard# · Click the Add consequence button and select Add Query Parameter. · In the input field that appears, enter the...
Read more >
How to solve the React useEffect Hook's infinite loop patterns
Solve the issue of infinite loops when using the useEffect Hook in React to more smoothly utilize the Hook for your app's side...
Read more >
How do I get a raw, compiled SQL query from a SQLAlchemy ...
This blogpost by Nicolas Cadou provides an updated answer. Quoting from the blog post, this is suggested and worked for me: from sqlalchemy.dialects...
Read more >
4 Examples of the useState Hook - Dave Ceddia
But with hooks, the state can be any type you want – you can useState with an array, useState an object, a number,...
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