How to display list number from find()?

If I have some data in my collection, and I find specific data by Collections.find({ field1: "good"}).count;
If it’s match 3 from 10 and I would like to display the list number from find result.
How can I do this work?

Item user
1    abc
2    def
3    ghi

I have tried “length” but it shows the Item like count.

I’m afraid you have to do a const totalCount = Collections.find().count to get the total count of all docs in a seperate call.

To minimize the amount of calls you make, if the total count doesn’t change that often, you could store that number somewhere for that session.

Collections.find({ field1: "good"}).reduce((col, value, index) => {
    item: index + 1,
    user: value.user
  return col;
}, []);

Hi manuel,
Thank you very much.
So if I would like to put your code in my project, how can I do that?

please see below my code.

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { Table, Alert, Button } from 'react-bootstrap';
import { Meteor } from 'meteor/meteor';
import { createContainer } from 'meteor/react-meteor-data';
import { Registers } from '../../api/registers';

const handleRemove = (registerId) => {
	if (confirm('Are you sure? This is permanent!')) {'registers.remove', registerId, (error) => {
			if (error) {
				console.log(error.reason, 'danger');
			} else {

const Sodaban = ({ sodaban, completedCount, match, history }) => (
		  	<div className="Sodaban">
    			<div className="page-header clearfix">
		      		<h4 className="pull-left">Sodaban </h4> <h4>Join {completedCount}</h4>
    			{sodaban.length ? <Table responsive>
		          		<th>First Name</th>
        		  		<th>Last Name</th>
        		  		<th>Bhumdharm Level</th>
      				{{ _id, regsId, salution, firstname, lastname, province, bhumdharmlevel, status }) => (
        		  	<tr key={_id}>
    		  </Table> : <Alert bsStyle="warning">Nobody yet!</Alert>}

Sodaban.propTypes = {
  sodaban: PropTypes.arrayOf(PropTypes.object).isRequired,
  completedCount: PropTypes.number.isRequired,
  match: PropTypes.object.isRequired,
  history: PropTypes.object.isRequired,

export default createContainer(() => {
  const subscription = Meteor.subscribe('registers');

  return {
    sodaban: Registers.find({ bhumdharmlevel: "sodaban", status: "come" }).fetch(),
    completedCount: Registers.find({ bhumdharmlevel: "sodaban", status: "come" }).count(),
}, Sodaban);

Tldr, instead of using collection.find use collection.find.reduce

1 Like

Thank you very much, manuel.