collectionNames
This commit is contained in:
parent
cef52ebf12
commit
378bc42393
2 changed files with 17 additions and 3 deletions
|
@ -28,7 +28,10 @@ module Database.MongoDB
|
||||||
-- * Connection
|
-- * Connection
|
||||||
Connection,
|
Connection,
|
||||||
connect, connectOnPort, conClose, disconnect,
|
connect, connectOnPort, conClose, disconnect,
|
||||||
-- * Basic database operations
|
-- * Database operations
|
||||||
|
Database,
|
||||||
|
collectionNames,
|
||||||
|
-- * Collection operations
|
||||||
Collection, FieldSelector, NumToSkip, NumToReturn, Selector,
|
Collection, FieldSelector, NumToSkip, NumToReturn, Selector,
|
||||||
QueryOpt(..),
|
QueryOpt(..),
|
||||||
UpdateFlag(..),
|
UpdateFlag(..),
|
||||||
|
@ -52,8 +55,9 @@ import qualified Data.ByteString.Lazy.UTF8 as L8
|
||||||
import Data.Int
|
import Data.Int
|
||||||
import Data.IORef
|
import Data.IORef
|
||||||
import qualified Data.List as List
|
import qualified Data.List as List
|
||||||
|
import Data.Maybe
|
||||||
import Data.Typeable
|
import Data.Typeable
|
||||||
import Database.MongoDB.BSON
|
import Database.MongoDB.BSON as BSON
|
||||||
import Database.MongoDB.Util
|
import Database.MongoDB.Util
|
||||||
import qualified Network
|
import qualified Network
|
||||||
import Network.Socket hiding (connect, send, sendTo, recv, recvFrom)
|
import Network.Socket hiding (connect, send, sendTo, recv, recvFrom)
|
||||||
|
@ -88,6 +92,14 @@ conClose = hClose . cHandle
|
||||||
disconnect :: Connection -> IO ()
|
disconnect :: Connection -> IO ()
|
||||||
disconnect = conClose
|
disconnect = conClose
|
||||||
|
|
||||||
|
-- | Return a list of collections in /Database/.
|
||||||
|
collectionNames :: Connection -> Database -> IO [Collection]
|
||||||
|
collectionNames c db = do
|
||||||
|
docs <- quickFind' c (db ++ ".system.namespaces") $ toBsonDoc []
|
||||||
|
let names = flip List.map docs $ \doc ->
|
||||||
|
fromBson $ fromJust $ BSON.lookup (L8.fromString "name") doc
|
||||||
|
return $ List.filter (not . List.elem '$') names
|
||||||
|
|
||||||
-- | An Itertaor over the results of a query. Use 'nextDoc' to get each
|
-- | An Itertaor over the results of a query. Use 'nextDoc' to get each
|
||||||
-- successive result document, or 'allDocs' or 'allDocs'' to get lazy or
|
-- successive result document, or 'allDocs' or 'allDocs'' to get lazy or
|
||||||
-- strict lists of results.
|
-- strict lists of results.
|
||||||
|
@ -146,6 +158,9 @@ toOpcode 2006 = OP_DELETE
|
||||||
toOpcode 2007 = OP_KILL_CURSORS
|
toOpcode 2007 = OP_KILL_CURSORS
|
||||||
toOpcode n = throw $ MongoDBInternalError $ "Got unexpected Opcode: " ++ show n
|
toOpcode n = throw $ MongoDBInternalError $ "Got unexpected Opcode: " ++ show n
|
||||||
|
|
||||||
|
-- | The name of a database.
|
||||||
|
type Database = String
|
||||||
|
|
||||||
-- | The full collection name. The full collection name is the
|
-- | The full collection name. The full collection name is the
|
||||||
-- concatenation of the database name with the collection name, using
|
-- concatenation of the database name with the collection name, using
|
||||||
-- a @.@ for the concatenation. For example, for the database @foo@
|
-- a @.@ for the concatenation. For example, for the database @foo@
|
||||||
|
|
1
TODO
1
TODO
|
@ -23,7 +23,6 @@ MongoDB
|
||||||
- pair mode connection
|
- pair mode connection
|
||||||
- operations on database objects
|
- operations on database objects
|
||||||
* getName
|
* getName
|
||||||
* getCollectionNames
|
|
||||||
* getCollection
|
* getCollection
|
||||||
* dropCollection
|
* dropCollection
|
||||||
* executeCommand
|
* executeCommand
|
||||||
|
|
Loading…
Reference in a new issue