var testcollection = db.getCollection(testcollectionname)
...
var c1= testcollection.aggregate([{$group: {_id: { $concat: [ "$LastName", ", ", "$FirstName", " ", {$ifNull:["$MiddleName",""]}] } , count : { $sum: 1}}},{$match: {count : { $gt : 1 }}}, {$project: {_id:1 , "duplicates":"$count"}}])
print(c1.itcount())c1.forEach(printjson)var c1= testcollection.aggregate([{$group: {_id: { $concat: [ "$LastName", ", ", "$FirstName", " ", {$ifNull:["$MiddleName",""]}] } , count : { $sum: 1}}},{$match: {count : { $gt : 1 }}}, {$project: {_id:1 , "duplicates":"$count"}}])
print(c1.itcount())
c1= testcollection.aggregate([{$group: {_id: { $concat: [ "$LastName", ", ", "$FirstName", " ", {$ifNull:["$MiddleName",""]}] } , count : { $sum: 1}}},{$match: {count : { $gt : 1 }}}, {$project: {_id:1 , "duplicates":"$count"}}])
c1.forEach(printjson)var c1= testcollection.aggregate([{$group: {_id: { $concat: [ "$LastName", ", ", "$FirstName", " ", {$ifNull:["$MiddleName",""]}] } , count : { $sum: 1}}},{$match: {count : { $gt : 1 }}}, {$project: {_id:1 , "duplicates":"$count"}}])
c1.itcount()
var c2= testcollection.aggregate([{$group: {_id: { $concat: [ "$LastName", ", ", "$FirstName", " ", {$ifNull:["$MiddleName",""]}] } , count : { $sum: 1}}},{$match: {count : { $gt : 1 }}}, {$project: {_id:1 , "duplicates":"$count"}}])
c2.forEach(printjson)var c1= testcollection.aggregate([{$group: {_id: { $concat: [ "$LastName", ", ", "$FirstName", " ", {$ifNull:["$MiddleName",""]}] } , count : { $sum: 1}}},{$match: {count : { $gt : 1 }}}, {$project: {_id:1 , "duplicates":"$count"}}])
c1.count()2018-01-13T20:22:08.149-0500 E QUERY [thread1] TypeError: c1.count is not a function :Hi Mike
but I get no output at all. If the cursor is exhausted of iterable data, I get that.
Actually, the itcount() method iterates and exhausts the cursor (see cursor.itcount()). This is why when you subsequently called c1.forEach(), nothing is printed as the cursor was exhausted.
but if c1 IS a cursor…why would count() throw an error.
This is because c1 was an aggregation cursor, which contains a different set of methods vs. a find() cursor. The list of methods available for an aggregation cursor can be found in Cursor Behavior.
I hope this clears it up. If you require more help, please post some example documents and what operation you need to do.
Best regards
Kevin