use ExtendedDefaultRules in example
This commit is contained in:
parent
c2ca221a6c
commit
e152f5b69b
3 changed files with 17 additions and 17 deletions
|
@ -1,9 +1,9 @@
|
||||||
{- |
|
{- |
|
||||||
Client interface to MongoDB database management system.
|
Client interface to MongoDB database management system.
|
||||||
|
|
||||||
Simple example below. Use with language extension /OvererloadedStrings/.
|
Simple example below. Use with language extensions /OvererloadedStrings/ & /ExtendedDefaultRules/.
|
||||||
|
|
||||||
> {-# LANGUAGE OverloadedStrings #-}
|
> {-# LANGUAGE OverloadedStrings, ExtendedDefaultRules #-}
|
||||||
>
|
>
|
||||||
> import Database.MongoDB
|
> import Database.MongoDB
|
||||||
> import Control.Monad.Trans (liftIO)
|
> import Control.Monad.Trans (liftIO)
|
||||||
|
@ -24,16 +24,16 @@ Simple example below. Use with language extension /OvererloadedStrings/.
|
||||||
> clearTeams = delete (select [] "team")
|
> clearTeams = delete (select [] "team")
|
||||||
>
|
>
|
||||||
> insertTeams = insertMany "team" [
|
> insertTeams = insertMany "team" [
|
||||||
> ["name" =: u"Yankees", "home" =: ["city" =: u"New York", "state" =: u"NY"], "league" =: u"American"],
|
> ["name" =: "Yankees", "home" =: ["city" =: "New York", "state" =: "NY"], "league" =: "American"],
|
||||||
> ["name" =: u"Mets", "home" =: ["city" =: u"New York", "state" =: u"NY"], "league" =: u"National"],
|
> ["name" =: "Mets", "home" =: ["city" =: "New York", "state" =: "NY"], "league" =: "National"],
|
||||||
> ["name" =: u"Phillies", "home" =: ["city" =: u"Philadelphia", "state" =: u"PA"], "league" =: u"National"],
|
> ["name" =: "Phillies", "home" =: ["city" =: "Philadelphia", "state" =: "PA"], "league" =: "National"],
|
||||||
> ["name" =: u"Red Sox", "home" =: ["city" =: u"Boston", "state" =: u"MA"], "league" =: u"American"] ]
|
> ["name" =: "Red Sox", "home" =: ["city" =: "Boston", "state" =: "MA"], "league" =: "American"] ]
|
||||||
>
|
>
|
||||||
> allTeams = rest =<< find (select [] "team") {sort = ["home.city" =: (1 :: Int)]}
|
> allTeams = rest =<< find (select [] "team") {sort = ["home.city" =: 1]}
|
||||||
>
|
>
|
||||||
> nationalLeagueTeams = rest =<< find (select ["league" =: u"National"] "team")
|
> nationalLeagueTeams = rest =<< find (select ["league" =: "National"] "team")
|
||||||
>
|
>
|
||||||
> newYorkTeams = rest =<< find (select ["home.state" =: u"NY"] "team") {project = ["name" =: (1 :: Int), "league" =: (1 :: Int)]}
|
> newYorkTeams = rest =<< find (select ["home.state" =: "NY"] "team") {project = ["name" =: 1, "league" =: 1]}
|
||||||
>
|
>
|
||||||
> printDocs title docs = liftIO $ putStrLn title >> mapM_ (print . exclude ["_id"]) docs
|
> printDocs title docs = liftIO $ putStrLn title >> mapM_ (print . exclude ["_id"]) docs
|
||||||
>
|
>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules #-}
|
||||||
|
|
||||||
import Database.MongoDB
|
import Database.MongoDB
|
||||||
import Control.Monad.Trans (liftIO)
|
import Control.Monad.Trans (liftIO)
|
||||||
|
@ -19,15 +19,15 @@ run = do
|
||||||
clearTeams = delete (select [] "team")
|
clearTeams = delete (select [] "team")
|
||||||
|
|
||||||
insertTeams = insertMany "team" [
|
insertTeams = insertMany "team" [
|
||||||
["name" =: u"Yankees", "home" =: ["city" =: u"New York", "state" =: u"NY"], "league" =: u"American"],
|
["name" =: "Yankees", "home" =: ["city" =: "New York", "state" =: "NY"], "league" =: "American"],
|
||||||
["name" =: u"Mets", "home" =: ["city" =: u"New York", "state" =: u"NY"], "league" =: u"National"],
|
["name" =: "Mets", "home" =: ["city" =: "New York", "state" =: "NY"], "league" =: "National"],
|
||||||
["name" =: u"Phillies", "home" =: ["city" =: u"Philadelphia", "state" =: u"PA"], "league" =: u"National"],
|
["name" =: "Phillies", "home" =: ["city" =: "Philadelphia", "state" =: "PA"], "league" =: "National"],
|
||||||
["name" =: u"Red Sox", "home" =: ["city" =: u"Boston", "state" =: u"MA"], "league" =: u"American"] ]
|
["name" =: "Red Sox", "home" =: ["city" =: "Boston", "state" =: "MA"], "league" =: "American"] ]
|
||||||
|
|
||||||
allTeams = rest =<< find (select [] "team") {sort = ["home.city" =: (1 :: Int)]}
|
allTeams = rest =<< find (select [] "team") {sort = ["home.city" =: 1]}
|
||||||
|
|
||||||
nationalLeagueTeams = rest =<< find (select ["league" =: u"National"] "team")
|
nationalLeagueTeams = rest =<< find (select ["league" =: "National"] "team")
|
||||||
|
|
||||||
newYorkTeams = rest =<< find (select ["home.state" =: u"NY"] "team") {project = ["name" =: (1 :: Int), "league" =: (1 :: Int)]}
|
newYorkTeams = rest =<< find (select ["home.state" =: "NY"] "team") {project = ["name" =: 1, "league" =: 1]}
|
||||||
|
|
||||||
printDocs title docs = liftIO $ putStrLn title >> mapM_ (print . exclude ["_id"]) docs
|
printDocs title docs = liftIO $ putStrLn title >> mapM_ (print . exclude ["_id"]) docs
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue