Because the final result is only one number, there should not be such an error. For debugging purposes, it is recommended to output the results of each step in the pipeline. Add { $limit: 3 } after the step to be output, do not run the subsequent steps, and run the output. If there is too much data and the result is too slow, add a limit at the beginning and run it on small data first.
Change it again and again and run it in the shell. If it is inconvenient, just write it to a file, in terminalin
$ mongo < agg_uv.js
Input redirection cannot be omitted, otherwise it will run in script mode, which is somewhat different from interactive mode.
Too much data and can’t be processed. You can use $project to select the next field first and then group it,
The syntax is correct. I tried the following data on my machine:
In addition to match, I use the following aggregation query:
The result is correct
Because the final result is only one number, there should not be such an error. For debugging purposes, it is recommended to output the results of each step in the pipeline. Add
{ $limit: 3 }
after the step to be output, do not run the subsequent steps, and run the output. If there is too much data and the result is too slow, add a limit at the beginning and run it on small data first.Change it again and again and run it in the shell. If it is inconvenient, just write it to a file, in
terminal
in$ mongo < agg_uv.js
Input redirection cannot be omitted, otherwise it will run in script mode, which is somewhat different from interactive mode.