David
David

Reputation: 63

How to use “$and” operator in Haskell MongoDB query

I am trying to use "$and" operator in Haskell mongoDB which is not working:

myFilter = do
   cursor <- MongoDB.find (MongoDB.select ["$and" =: [["field1" =: "test1"], ["field2" =: "test2"], ["field3" =: "test3"]]],  "db") 
   rest cursor

Thanks in advance.

Upvotes: 0

Views: 176

Answers (1)

Steven Shaw
Steven Shaw

Reputation: 6249

You have an unnecessary comma before "db" which is causing a type error.

Try this:

myFilter = do
   cursor <- MongoDB.find (MongoDB.select ["$and" =: [["field1" =: "test1"], ["field2" =: "test2"], ["field3" =: "test3"]]]  "db")
   rest cursor

Note:

  • you don't really need to use "$and" because it is the default.
  • where you specify "db" is the name of a collection.

Upvotes: 3

Related Questions