[SERVER-35922] listCollections can't filter on collection options when using nameOnly Created: 29/Jun/18  Updated: 06/Dec/22  Resolved: 13/Jul/18

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: 4.0.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: David Golden Assignee: Backlog - Storage Execution Team
Resolution: Won't Fix Votes: 0
Labels: nyc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DOCS-11858 listCollection filter plus nameOnly o... Closed
Assigned Teams:
Storage Execution
Operating System: ALL
Steps To Reproduce:

MongoDB Enterprise > db.createCollection("cappitycapcap", {capped:true, size:100})
{ "ok" : 1 }
MongoDB Enterprise > db.runCommand({listCollections:1, filter:{"options.capped":true}, nameOnly: true})
{
        "cursor" : {
                "id" : NumberLong(0),
                "ns" : "lcbug.$cmd.listCollections",
                "firstBatch" : [ ]
        },
        "ok" : 1
}
MongoDB Enterprise > db.runCommand({listCollections:1, filter:{"options.capped":true}})
{
        "cursor" : {
                "id" : NumberLong(0),
                "ns" : "lcbug.$cmd.listCollections",
                "firstBatch" : [
                        {
                                "name" : "cappitycapcap",
                                "type" : "collection",
                                "options" : {
                                        "capped" : true,
                                        "size" : 256
                                },
                                "info" : {
                                        "readOnly" : false,
                                        "uuid" : UUID("abf81435-62d6-4247-85c6-6bc4bc9bfff2")
                                },
                                "idIndex" : {
                                        "v" : 2,
                                        "key" : {
                                                "_id" : 1
                                        },
                                        "name" : "_id_",
                                        "ns" : "lcbug.cappitycapcap"
                                }
                        }
                ]
        },
        "ok" : 1
}

Participants:

 Description   

When using listCollections with the nameOnly option and a filter, it looks like the filter is applied after retrieving only name information.

The documentation isn't clear that this is what should occur and the behavior could be surprising to users.

Another possible improvement would be to have the command fail if nameOnly is true and the filter contains any keys other than name.



 Comments   
Comment by David Golden [ 06/Jul/18 ]

I think it's clearest to say "nameOnly" means you get to search on name only, regardless of the capabilities of the underlying command.

Comment by Eric Milkie [ 06/Jul/18 ]

During our discussion it was pointed out that it might be hard to determine which filters apply with nameOnly, since the filter is a Match Expression, which can include operators. Additionally, since nameOnly belies its name and returns not only collection names but also their types, you can also successfully filter on type.

Comment by David Golden [ 06/Jul/18 ]

Works for me. I already updated the driver spec to prohibit nameOnly with filters on anything other than name, so I think we're in sync.

Comment by Eric Milkie [ 06/Jul/18 ]

Decided to document this behavior and no further changes to the code.

Comment by Eric Milkie [ 06/Jul/18 ]

I am leaning towards having the command fail, as the only purpose for using the "nameOnly" option is for efficiency, to avoid taking collection locks. If you want to filter on fields other than the collection name, you'll have to take collection locks anyway. The error message can state that filter with nameOnly can only filter on names and no other fields.

Generated at Thu Feb 08 04:41:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.