On this page:
3.1Servers
3.3.1Indexing
3.4Cursors
top
up

3Basic OperationsπŸ”— i

The basic API of MongoDB is provided by this module.

3.1ServersπŸ”— i

procedure

( mongo? x)boolean?

x:any/c
A test for Mongo servers.

procedure

( create-mongo [#:hosthost#:portport])mongo?

host:string ="localhost"
port:port-number? =27017
Creates a connection to the specified Mongo server.

procedure

( close-mongo! m)void?

m:mongo?
Closes the connection to the Mongo server.

Returns information about the databases on a server.

procedure

( mongo-db-names m)(listof string? )

m:mongo?
Returns the names of the databases on the server.

3.2DatabasesπŸ”— i

struct

(struct mongo-db (mongoname)
#:extra-constructor-namemake-mongo-db )
mongo:mongo?
name:string?
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.

procedure

( mongo-db-collections db)(listof string? )

Returns a list of collection names in the database.

procedure

name
#:capped?capped?
#:sizesize
[ #:maxmax])
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.

Drops a collection from the database.

Drops a database from its server.

Defined as (symbols 'none'low'all).
Returns the profiling level of the database.
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.

procedure

( mongo-db-valid-collection? dbname)boolean?

name:string?
Returns #t if name is a valid collection.

3.3CollectionsπŸ”— i

struct

#:extra-constructor-namemake-mongo-collection )
name:string?
A structure representing a Mongo collection.

Drops the collection from its database.
Returns #t if mc is a valid collection.
Returns the full name of the collection.

procedure

query
[ #:tailable?tailable?
#:slave-okay?slave-okay?
#:no-timeout?no-timeout?
#:selectorselector
#:skipskip
#:limitlimit])
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.

procedure

( mongo-collection-insert-docs! mcdocs)void

docs:(sequenceofbson-document/c )
Inserts a sequence of documents into the collection.
Insert an document into the collection.
Inserts any number of documents into the collection.

Removes documents matching the selector. Refer to Removing for more details.

Modifies all documents matching the selector according to mod. Refer to Modifier Operations for more details.

Replaces the first document matching the selector with obj.

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.

Returns the number of documents matching the query.

3.3.1IndexingπŸ”— i

Refer to Indexes for more details on indexing.

procedure

( mongo-collection-index! mcspec[name])void

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.4CursorsπŸ”— i

Query results are returned as Mongo cursors.

A Mongo cursor is a sequence of BSON documents.

procedure

( mongo-cursor? x)boolean?

x:any/c
A test for Mongo cursors.
Returns #t if the cursor has no more answers. #f otherwise.

procedure

( mongo-cursor-kill! mc)void

Frees the server resources for the cursor.

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /