mongodb-haskell / mongodb

MongoDB driver for Haskell
http://hackage.haskell.org/package/mongoDB
Apache License 2.0
172 stars 47 forks source link

mongo 6: cannot request a collection with a dot (".") in its name #146

Closed pierreMizrahi closed 1 year ago

pierreMizrahi commented 1 year ago

The following test case:

  describe "collectionWithDot" $ do
    it "uses a collection with dots in the name" $ do
      let coll = "collection.with.dot"
      _id <- db $ insert coll ["name" =: "jack", "color" =: "blue"]
      Just doc <- db $ findOne (select ["name" =: "jack"] coll)
      doc !? "color" `shouldBe` (Just "blue")

fails with mongo 6.0. It succeeds with versions that do not use OP_MSG, and succeeds if the dots are replaced by underscores in the collection name.

Collections with dot are supported by both the mongo client and the python client.

This is due to https://github.com/mongodb-haskell/mongodb/blob/995087e9a01c0a231a99f9e29d1680b0f4269484/Database/MongoDB/Query.hs#L1336

Which returns the rightmost suffix.

I will submit a PR that only drops the prefix until the first dot. It should be safe because the mongo spec states that dtabase names should not contain a dot, both on windows and linux platforms:

https://www.mongodb.com/docs/manual/reference/limits/#naming-restrictions

Note that the doc does not give such restrictions on collection names, as only "$" and "system." are forbidden.