2010-07-03 17:15:30 +00:00
|
|
|
{- |
|
|
|
|
Client interface to MongoDB server(s).
|
|
|
|
|
2010-07-27 22:01:05 +00:00
|
|
|
Simple example below. Use with language extension /OvererloadedStrings/.
|
2010-07-03 17:15:30 +00:00
|
|
|
|
|
|
|
> {-# LANGUAGE OverloadedStrings #-}
|
|
|
|
>
|
|
|
|
> import Database.MongoDB
|
2010-07-27 22:01:05 +00:00
|
|
|
> import Data.UString (u)
|
|
|
|
> import Control.Monad.Trans (liftIO)
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
|
|
|
> main = do
|
2010-07-27 22:01:05 +00:00
|
|
|
> ee <- runNet $ do
|
|
|
|
> conn <- connect (host "127.0.0.1")
|
|
|
|
> runConn run conn
|
|
|
|
> print ee
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
|
|
|
> run = useDb "baseball" $ do
|
|
|
|
> clearTeams
|
|
|
|
> insertTeams
|
|
|
|
> print' "All Teams" =<< allTeams
|
|
|
|
> print' "National League Teams" =<< nationalLeagueTeams
|
|
|
|
> print' "New York Teams" =<< newYorkTeams
|
|
|
|
>
|
|
|
|
> clearTeams = delete (select [] "team")
|
|
|
|
>
|
|
|
|
> insertTeams = insertMany "team" [
|
2010-07-27 22:01:05 +00:00
|
|
|
> ["name" =: u"Yankees", "home" =: ["city" =: u"New York", "state" =: u"NY"], "league" =: u"American"],
|
|
|
|
> ["name" =: u"Mets", "home" =: ["city" =: u"New York", "state" =: u"NY"], "league" =: u"National"],
|
|
|
|
> ["name" =: u"Phillies", "home" =: ["city" =: u"Philadelphia", "state" =: u"PA"], "league" =: u"National"],
|
|
|
|
> ["name" =: u"Red Sox", "home" =: ["city" =: u"Boston", "state" =: u"MA"], "league" =: u"American"] ]
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
2010-07-27 22:01:05 +00:00
|
|
|
> allTeams = rest =<< find (select [] "team") {sort = ["city" =: (1 :: Int)]}
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
2010-07-27 22:01:05 +00:00
|
|
|
> nationalLeagueTeams = rest =<< find (select ["league" =: u"National"] "team")
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
2010-07-27 22:01:05 +00:00
|
|
|
> newYorkTeams = rest =<< find (select ["home.state" =: u"NY"] "team") {project = ["name" =: (1 :: Int), "league" =: (1 :: Int)]}
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
|
|
|
> print' title docs = liftIO $ putStrLn title >> mapM_ print docs
|
|
|
|
-}
|
2010-06-15 03:14:40 +00:00
|
|
|
|
|
|
|
module Database.MongoDB (
|
|
|
|
module Data.Bson,
|
|
|
|
module Database.MongoDB.Connection,
|
|
|
|
module Database.MongoDB.Query,
|
|
|
|
module Database.MongoDB.Admin
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.Bson
|
|
|
|
import Database.MongoDB.Connection
|
|
|
|
import Database.MongoDB.Query
|
|
|
|
import Database.MongoDB.Admin
|