Atlas text search combined with other field search and count?

I need to do combined text search and filter by another value in the collection, while also returning the total count of matching records.

await Person.aggregate([
  {
	$search: {
	  index: 'people_text_index',
	  'text': {
		'query': filter.query,
		'path': {
		  wildcard: '*'
		}
	  },
	  count: {
		type: 'total'
	  }
	}
  },
  {
	$match: {
	  deleted: { $ne: true }
	}
  },
  {
	$count: 'count'
  },
  {
	$addFields: {
	  'mongoMeta': '$$SEARCH_META'
	}
  },
  { $skip : offset },
  { $limit: limit }
]);

If I do this I get a result with form [ { count: 26 } ]. If I want both the total count and the results, should I be running this twice? Once with the $count and once without?

Hi @Andre-John_Mas1 ,

I think you might be interested in adding a $facet stage instead if just the $count .

You can have one facet field to do the $count while the other gets a limited batch using $limit of the search results.

Let me know if that make sense to you

Thanks
Pavel