3 Basic Operations
(require (planet jaymccarthy/mongodb:1:11/basic/main)) |
The basic API of MongoDB is provided by this module.
3.1 Servers
A test for Mongo servers.
(create-mongo [#:host host #:port port]) → mongo? host : string = "localhost" port : port-number? = 27017
Creates a connection to the specified Mongo server.
(close-mongo! m) → void? m : mongo?
Closes the connection to the Mongo server.
(mongo-list-databases m) → (vectorof bson-document/c) m : mongo?
Returns information about the databases on a server.
Returns the names of the databases on the server.
3.2 Databases
A structure representing a Mongo database. The mongo field is mutable.
Executes command cmd on the database db and returns Mongo’s response. Refer to List of Database Commands for more details.
Returns a list of collection names in the database.
(mongo-db-create-collection! db name #:capped? capped? #:size size [ #:max max]) → mongo-collection? db : mongo-db? name : string? capped? : boolean? size : number? max : (or/c false/c number?) = #f
Creates a new collection in the database and returns a handle to it. Refer to Capped Collections for details on the options.
(mongo-db-drop-collection! db name) → bson-document/c db : mongo-db? name : string?
Drops a collection from the database.
Drops a database from its server.
mongo-db-profiling/c : contract?
Returns the profiling level of the database.
(set-mongo-db-profiling! db v) → boolean? db : mongo-db? v : mongo-db-profiling/c
Sets the profiling level of the database. Returns #t on success.
Returns the profiling information from the database. Refer to Database Profiler for more details.
Returns #t if name is a valid collection.
3.3 Collections
(struct mongo-collection (db name) #:extra-constructor-name make-mongo-collection) db : mongo-db? name : string?
A structure representing a Mongo collection.
(mongo-collection-drop! mc) → void mc : mongo-collection?
Drops the collection from its database.
(mongo-collection-valid? mc) → boolean? mc : mongo-collection?
Returns #t if mc is a valid collection.
(mongo-collection-full-name mc) → string? mc : mongo-collection?
Returns the full name of the collection.
(mongo-collection-find mc query [ #:tailable? tailable? #:slave-okay? slave-okay? #:no-timeout? no-timeout? #:selector selector #:skip skip #:limit limit]) → mongo-cursor? mc : mongo-collection? query : bson-document/c tailable? : boolean? = #f slave-okay? : boolean? = #f no-timeout? : boolean? = #f selector : (or/c false/c bson-document/c) = #f skip : int32? = 0 limit : (or/c false/c int32?) = #f
Performs a query in the collection. Refer to Querying for more details.
If limit is #f, then a limit of 2 is sent. This is the smallest limit that creates a server-side cursor, because 1 is interpreted as -1.
(mongo-collection-insert-docs! mc docs) → void mc : mongo-collection? docs : (sequenceof bson-document/c)
Inserts a sequence of documents into the collection.
(mongo-collection-insert-one! mc doc) → void mc : mongo-collection? doc : bson-document/c
Insert an document into the collection.
(mongo-collection-insert! mc doc ...) → void mc : mongo-collection? doc : bson-document/c
Inserts any number of documents into the collection.
(mongo-collection-remove! mc sel) → void mc : mongo-collection? sel : bson-document/c
Removes documents matching the selector. Refer to Removing for more details.
(mongo-collection-modify! mc sel mod) → void mc : mongo-collection? sel : bson-document/c mod : bson-document/c
Modifies all documents matching the selector according to mod. Refer to Modifier Operations for more details.
(mongo-collection-replace! mc sel doc) → void mc : mongo-collection? sel : bson-document/c doc : bson-document/c
Replaces the first document matching the selector with obj.
(mongo-collection-repsert! mc sel doc) → void mc : mongo-collection? sel : bson-document/c doc : bson-document/c
If a document matches the selector, it is replaced; otherwise the document is inserted. Refer to Upserts with Modifiers for more details on using modifiers.
(mongo-collection-count mc [query]) → exact-integer? mc : mongo-collection? query : bson-document/c = empty
Returns the number of documents matching the query.
3.3.1 Indexing
Refer to Indexes for more details on indexing.
(mongo-collection-index! mc spec [name]) → void mc : mongo-collection? spec : bson-document/c name : string? = ....
Creates an index of the collection. A name will be automatically generated if not specified.
Queries for index information.
Drops an index by name.
3.4 Cursors
Query results are returned as Mongo cursors.
A Mongo cursor is a sequence of BSON documents.
A test for Mongo cursors.
(mongo-cursor-done? mc) → boolean? mc : mongo-cursor?
Returns #t if the cursor has no more answers. #f otherwise.
(mongo-cursor-kill! mc) → void mc : mongo-cursor?
Frees the server resources for the cursor.