2010-07-03 17:15:30 +00:00
|
|
|
{- |
|
2010-10-27 20:13:23 +00:00
|
|
|
Client interface to MongoDB database management system.
|
2010-07-03 17:15:30 +00:00
|
|
|
|
2015-10-19 13:39:39 +00:00
|
|
|
Simple example below. Use with language extensions /OverloadedStrings/ & /ExtendedDefaultRules/.
|
2010-07-03 17:15:30 +00:00
|
|
|
|
2014-07-07 05:05:03 +00:00
|
|
|
|
2010-07-03 17:15:30 +00:00
|
|
|
> import Database.MongoDB
|
2010-07-27 22:01:05 +00:00
|
|
|
> import Control.Monad.Trans (liftIO)
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
|
|
|
> main = do
|
2014-07-07 05:05:03 +00:00
|
|
|
> pipe <- connect (host "127.0.0.1")
|
2011-07-09 02:13:47 +00:00
|
|
|
> e <- access pipe master "baseball" run
|
2011-07-05 14:37:01 +00:00
|
|
|
> close pipe
|
2010-10-27 20:13:23 +00:00
|
|
|
> print e
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
2011-07-05 14:37:01 +00:00
|
|
|
> run = do
|
2010-07-03 17:15:30 +00:00
|
|
|
> clearTeams
|
|
|
|
> insertTeams
|
2011-07-21 20:39:19 +00:00
|
|
|
> allTeams >>= printDocs "All Teams"
|
|
|
|
> nationalLeagueTeams >>= printDocs "National League Teams"
|
|
|
|
> newYorkTeams >>= printDocs "New York Teams"
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
|
|
|
> clearTeams = delete (select [] "team")
|
|
|
|
>
|
|
|
|
> insertTeams = insertMany "team" [
|
2011-07-30 16:49:37 +00:00
|
|
|
> ["name" =: "Yankees", "home" =: ["city" =: "New York", "state" =: "NY"], "league" =: "American"],
|
|
|
|
> ["name" =: "Mets", "home" =: ["city" =: "New York", "state" =: "NY"], "league" =: "National"],
|
|
|
|
> ["name" =: "Phillies", "home" =: ["city" =: "Philadelphia", "state" =: "PA"], "league" =: "National"],
|
|
|
|
> ["name" =: "Red Sox", "home" =: ["city" =: "Boston", "state" =: "MA"], "league" =: "American"] ]
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
2011-07-30 16:49:37 +00:00
|
|
|
> allTeams = rest =<< find (select [] "team") {sort = ["home.city" =: 1]}
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
2011-07-30 16:49:37 +00:00
|
|
|
> nationalLeagueTeams = rest =<< find (select ["league" =: "National"] "team")
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
2011-07-30 16:49:37 +00:00
|
|
|
> newYorkTeams = rest =<< find (select ["home.state" =: "NY"] "team") {project = ["name" =: 1, "league" =: 1]}
|
2010-07-03 17:15:30 +00:00
|
|
|
>
|
2010-12-27 05:23:02 +00:00
|
|
|
> printDocs title docs = liftIO $ putStrLn title >> mapM_ (print . exclude ["_id"]) docs
|
|
|
|
>
|
2010-07-03 17:15:30 +00:00
|
|
|
-}
|
2010-06-15 03:14:40 +00:00
|
|
|
|
|
|
|
module Database.MongoDB (
|
2013-12-26 14:57:33 +00:00
|
|
|
module Data.Bson,
|
|
|
|
module Database.MongoDB.Connection,
|
|
|
|
module Database.MongoDB.Query,
|
|
|
|
module Database.MongoDB.Admin
|
2010-06-15 03:14:40 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.Bson
|
|
|
|
import Database.MongoDB.Connection
|
|
|
|
import Database.MongoDB.Query
|
|
|
|
import Database.MongoDB.Admin
|
2010-12-20 02:08:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
{- Authors: Tony Hannan <tony@10gen.com>
|
2011-07-09 02:13:47 +00:00
|
|
|
Copyright 2010-11 10gen Inc.
|
2010-12-20 02:08:53 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -}
|