persistent-mongoDB-1.2.1.1: Backend for the persistent library using mongoDB.

Safe HaskellNone

Database.Persist.MongoDB

Contents

Description

Use persistent-mongodb the same way you would use other persistent libraries and refer to the general persistent documentation. There are some new MongoDB specific filters under the filters section. These help extend your query into a nested document.

However, at some point you will find the normal Persistent APIs lacking. and want lower level-level MongoDB access. There are functions available to make working with the raw driver easier: they are under the Entity conversion section. You should still use the same connection pool that you are using for Persistent.

MongoDB is a schema-less database. The MongoDB Persistent backend does not help perform migrations. Unlike SQL backends, uniqueness constraints cannot be created for you. You must place a unique index on unique fields.

Synopsis

Entity conversion

collectionName :: PersistEntity record => record -> TextSource

entityToDocument :: PersistEntity record => record -> [Field]Source

convert a PersistEntity into document fields. unlike toInsertFields, nulls are included.

entityToFields :: PersistEntity record => record -> [Field]Source

Deprecated: Please use entityToDocument instead

Deprecated, use the better named entityToDocument

toInsertFields :: forall record. PersistEntity record => record -> [Field]Source

convert a PersistEntity into document fields. for inserts only: nulls are ignored so they will be unset in the document. entityToFields includes nulls

docToEntityEither :: forall record. PersistEntity record => Document -> Either Text (Entity record)Source

docToEntityThrow :: forall m record. (MonadIO m, PersistEntity record) => Document -> m (Entity record)Source

MongoDB specific Filters

You can find example usage for all of Persistent in our test cases: https://github.com/yesodweb/persistent/blob/master/persistent-test/EmbedTest.hs#L144

These filters create a query that reaches deeper into a document with nested fields.

(->.) :: forall val nes nes1. PersistEntity nes1 => EntityField val nes1 -> EntityField nes1 nes -> NestedField val nesSource

Point to a nested field to query. Used for the final level of nesting with nestEq or other operators.

(~>.) :: forall val nes nes1. PersistEntity nes1 => EntityField val nes1 -> NestedField nes1 nes -> NestedField val nesSource

Point to a nested field to query. This level of nesting is not the final level. Use (->.) to point to the final level is

(?->.) :: forall val nes nes1. PersistEntity nes1 => EntityField val (Maybe nes1) -> EntityField nes1 nes -> NestedField val nesSource

Same as (->.), but Works against a Maybe type

(?~>.) :: forall val nes nes1. PersistEntity nes1 => EntityField val (Maybe nes1) -> NestedField nes1 nes -> NestedField val nesSource

Same as (~>.), but Works against a Maybe type

nestEq :: forall v typ. (PersistField typ, PersistEntityBackend v ~ MongoBackend) => NestedField v typ -> typ -> Filter vSource

The normal Persistent equality test (==.) is not generic enough. Instead use this with the drill-down operaters (->.) or (?->.)

multiEq :: forall v typ. (PersistField typ, PersistEntityBackend v ~ MongoBackend) => EntityField v [typ] -> typ -> Filter vSource

use to see if an embedded list contains an item

using connections

createMongoDBPoolSource

Arguments

:: (MonadIO m, Applicative m) 
=> Database 
-> HostName 
-> PortID 
-> Maybe MongoAuth 
-> Int

pool size (number of stripes)

-> Int

stripe size (number of connections per stripe)

-> NominalDiffTime

time a connection is left idle before closing

-> m ConnectionPool 

runMongoDBPoolDef :: (MonadIO m, MonadBaseControl IO m) => Action m a -> ConnectionPool -> m aSource

use default AccessMode

data MongoConf Source

Information required to connect to a mongo database

data MongoBackend Source

Instances

PathPiece (KeyBackend MongoBackend entity)

ToPathPiece is used to convert a key to/from text

using raw MongoDB pipes

createMongoDBPipePoolSource

Arguments

:: (MonadIO m, Applicative m) 
=> HostName 
-> PortID 
-> Int

pool size (number of stripes)

-> Int

stripe size (number of connections per stripe)

-> NominalDiffTime

time a connection is left idle before closing

-> m PipePool 

A pool of plain MongoDB pipes. The database parameter has not yet been applied yet. This is useful for switching between databases (on the same host and port) Unlike the normal pool, no authentication is available

runMongoDBPipePool :: (MonadIO m, MonadBaseControl IO m) => AccessMode -> Database -> Action m a -> PipePool -> m aSource

run a pool created with createMongoDBPipePool

Key conversion helpers

oidToKey :: PersistEntity entity => ObjectId -> Key entitySource

network type

data PortID

Instances

MongoDB driver types

type Database = Text

data Action m a

A monad on top of m (which must be a MonadIO) that may access the database and may fail with a DB Failure

Instances

MonadTrans Action 
MonadTransControl Action 
(MonadIO m, MonadBaseControl b m) => MonadBaseControl b (Action m) 
MonadBase b m => MonadBase b (Action m) 
Monad m => MonadError Failure (Action m) 
Monad m => Monad (Action m) 
Functor m => Functor (Action m) 
(Monad m, Functor m) => Applicative (Action m) 
MonadThrow m => MonadThrow (Action m) 
(MonadBaseControl IO m, Applicative m, Functor m) => MonadDB (Action m) 
(Applicative m, Functor m, MonadIO m, MonadBaseControl IO m) => PersistUnique (Action m) 
(Applicative m, Functor m, MonadIO m, MonadBaseControl IO m) => PersistQuery (Action m) 
(Applicative m, Functor m, MonadIO m, MonadBaseControl IO m) => PersistStore (Action m) 
MonadIO m => MonadIO (Action m) 

data AccessMode

Type of reads and writes to perform

Constructors

ReadStaleOk

Read-only action, reading stale data from a slave is OK.

UnconfirmedWrites

Read-write action, slave not OK, every write is fire & forget.

ConfirmWrites GetLastError

Read-write action, slave not OK, every write is confirmed with getLastError.

Instances

(=:) :: Val v => Label -> v -> Field

Field with given label and typed value

Database.Persist