3 Basic Operations
(require db/mongodb/basic/main) | package: mongodb |
The basic API of MongoDB is provided by this module.
3.1 Servers
procedure
(create-mongo [#:host host #:port port]) → mongo?
host : string = "localhost" port : port-number? = 27017
procedure
(close-mongo! m) → void?
m : mongo?
procedure
m : mongo?
procedure
(mongo-db-names m) → (listof string?)
m : mongo?
3.2 Databases
struct
(struct mongo-db (mongo name) #:extra-constructor-name make-mongo-db) mongo : mongo? name : string?
procedure
(mongo-db-execute-command! db cmd) → bson-document/c
db : mongo-db? cmd : bson-document/c
procedure
(mongo-db-collections db) → (listof string?)
db : mongo-db?
procedure
(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
procedure
(mongo-db-drop-collection! db name) → bson-document/c
db : mongo-db? name : string?
procedure
(mongo-db-drop db) → bson-document/c
db : mongo-db?
value
procedure
db : mongo-db?
procedure
(set-mongo-db-profiling! db v) → boolean?
db : mongo-db? v : mongo-db-profiling/c
procedure
db : mongo-db?
procedure
(mongo-db-valid-collection? db name) → boolean?
db : mongo-db? name : string?
3.3 Collections
struct
(struct mongo-collection (db name) #:extra-constructor-name make-mongo-collection) db : mongo-db? name : string?
procedure
(mongo-collection-drop! mc) → void
mc : mongo-collection?
procedure
(mongo-collection-valid? mc) → boolean?
mc : mongo-collection?
procedure
mc : mongo-collection?
procedure
(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
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! mc docs) → void
mc : mongo-collection? docs : (sequenceof bson-document/c)
procedure
(mongo-collection-insert-one! mc doc) → void
mc : mongo-collection? doc : bson-document/c
procedure
(mongo-collection-insert! mc doc ...) → void
mc : mongo-collection? doc : bson-document/c
procedure
(mongo-collection-remove! mc sel) → void
mc : mongo-collection? sel : bson-document/c
procedure
(mongo-collection-modify! mc sel mod) → void
mc : mongo-collection? sel : bson-document/c mod : bson-document/c
procedure
(mongo-collection-replace! mc sel doc) → void
mc : mongo-collection? sel : bson-document/c doc : bson-document/c
procedure
(mongo-collection-repsert! mc sel doc) → void
mc : mongo-collection? sel : bson-document/c doc : bson-document/c
procedure
(mongo-collection-count mc [query]) → exact-integer?
mc : mongo-collection? query : bson-document/c = empty
3.3.1 Indexing
Refer to Indexes for more details on indexing.
procedure
(mongo-collection-index! mc spec [name]) → void
mc : mongo-collection? spec : bson-document/c name : string? = ....
procedure
mc : mongo-collection?
procedure
(mongo-collection-drop-index! mc name) → void
mc : mongo-collection? name : string?
3.4 Cursors
Query results are returned as Mongo cursors.
A Mongo cursor is a sequence of BSON documents.
procedure
(mongo-cursor? x) → boolean?
x : any/c
procedure
(mongo-cursor-done? mc) → boolean?
mc : mongo-cursor?
procedure
(mongo-cursor-kill! mc) → void
mc : mongo-cursor?