MongoDB filters aggregate query results

  mongodb, question

If you want to use java for grouping query, it seems that version 2.4 of java driver package does not support db.collection.aggregate syntax, so you are forced to use db.collection.group () instead.
Requirement: To achieve the same function as SQL with Mongo:
select number from user group by number having count(*) = 1

Using aggregate, you can do this:

db.user.aggregate(
 {$group:{_id:"$number",total:{$sum:1}}},
 {$match:{total:1}}
 );

Now use the group method instead:

db.user.group({
 key : {number:1},
 cond : {count:1},
 initial : {count: 0},
 reduce : function Reduce(doc, out) {
 out.count +=1;
 },
 finalize : function Finalize(out) {
 return out;
 }
 });

If no results are found, how can they be solved?

I tried another method, but it still failed.

db.user.group({
 key : {number:1},
 cond : {},
 initial : {count: 0},
 reduce : function Reduce(doc, out) {
 out.count +=1;
 },
 finalize : function Finalize(out) {
 if(out.count==1){
 return out;
 }
 }
 });

What’s the use of return in finalize?