[SERVER-49098] countDocuments() set query to {} if it's empty Created: 25/Jun/20 Updated: 27/Oct/23 Resolved: 12/Oct/20 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Danilo Nobrega | Assignee: | Jonathan Streets (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Participants: |
| Description |
|
The shell does not set the query to {} for countDocuments() if it's empty. i.e. the following returns an error from ADL as it is converted to a $match with no document passed in. > db.data.countDocuments()
countDocuments() doesn’t seem to work with federated queries:> db.data.count() what happens when you run aggregate command and {$count:'c'} > db.data.aggregate({$count:‘c’}) { “c” : 10000 }it works that's all that the shell helper does for countDocuments can you type db.data.countDocuments without the () and paste what you see? oh I bet I know - you need to run it as db.data.countDocuments({}) I bet. bug in the shell query should be `query = query || {} ` same as options. it's a bug in the shell component. need to file a Jira ticket on it. surprised if there isn't one already though but then why didn't we fix it? > db.data.countDocuments { “use strict”; let pipeline = [ {“$match”: query}]; { pipeline.push( {“$skip”: options.skip}); { pipeline.push( {“$limit”: options.limit}); }}); // countDocument options other than filter, skip, and limit, are added to the aggregate command. if (options.maxTimeMS) { aggregateOptions.maxTimeMS = options.maxTimeMS; }if (options.collation) { aggregateOptions.collation = options.collation; } // Format cursor into an array. return 0; Yeah it’s missing a line. Should set query to {} if it’s empty. > db.data.countDocuments({}) |
| Comments |
| Comment by Danilo Nobrega [ 13/Oct/20 ] |
|
jonathan.streets alright. I thought I would flag it as a bug, but if it is clear in the documentation, I guess that's acceptable. |
| Comment by Jonathan Streets (Inactive) [ 12/Oct/20 ] |
|
We haven’t heard back from you for some time, so I’m going to mark this ticket as resolved. If this is still an issue for you, please provide additional information and we will reopen the ticket. Regards, Jon |
| Comment by Jonathan Streets (Inactive) [ 13/Jul/20 ] |
|
Issue: db.collection.countDocuments() with no arguments returns an error. The documentation for countDocuments() states in the examples section, to get a count of documents one can use db.orders.countDocuments({}) e.g. The following mongo shell commands complete successfully:
The following command
returns an error { "ok" : 0, "errmsg" : "the match filter must be an expression in an object", "code" : 15959, "codeName" : "Location15959" }
danilo.nobrega, i think this is how the command is meant to work ? |