MongoDB: queries for nested documents are not formed correctly #194

Closed
zzat opened this Issue Jan 8, 2014 · 3 comments

Projects

None yet

2 participants

@zzat
zzat commented Jan 8, 2014

While using nestEq for querying nested fields, fields having underscore('_') do not appear properly in the final (mongo)query formed.
For Eg:

-- nested data model
Person
    name String
    address Address
    deriving Show
Address
   house_no String
   street String
   deriving Show

 selectList [PersonAddress ->. AddressHouse_no `nestEq`  "1"] []

For the above code, final query formed should have been like db.person.find({ "address.house_no" : "1" }) (note that underscore in house no) but in profiler it appears like: "query" : { "address.houseNo" : "1" } (without underscore and caps 'n')

Dunno if I'm looking in the right direction but I think its caused by this line of mongoFilterToDoc function in MongoDB.hs joinFN (fst':rst') = fst'```T.append```(T.concat (map (\t -> (toUpper . T.head $ t)```T.cons```(T.tail t)) rst'))

PS: I tested this for persistent-mongoDB-1.2.3
Query for 1.3.0 would be probably like this selectList [PersonAddress &->. AddressHouse_no```nestEq```"1"] []

@gregwebs
Member
gregwebs commented Jan 8, 2014

yeah, it change to &->., ->. queries an embedded array.
Thanks for the report! Lets add this to the persistent test suite.

@zzat
zzat commented Jan 9, 2014

I think changing line 571 in MongoDB.hs to this will fix it for names with underscore

joinFN (fst':rst') = fst' `T.append`  ("_" `T.append` (T.intercalate "_" (map (\t -> (toLower . T.head $ t) `T.cons` (T.tail t)) rst')))
@gregwebs
Member

closing in favor of #239. I have always used upperCaseSettings, and the current code is hard-coded to that.

@gregwebs gregwebs closed this Jun 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment