Xbasic

mongo_getDocument Function

Syntax

P result = mongo_getDocument(C mongoURL_or_connectionString, C databaseName, C collection, C id [, C fields])

Arguments

mongoURL_or_connectionStringCharacter

A Mongo AlphaDAO connection string or base URL.

databaseNameCharacter

The name of the MongoDB database.

collectionCharacter

The name of the collection.

idCharacter

The ID of the document to retrieve.

fieldsCharacter

A comma delimited list of fields to retrieve (e.g. "name,address"). If blank, all fields are returned.

Returns

resultPointer

Returns an object with the following properties:

errorLogical

.t. if an error occurred.

resultCharacter

The JSON string representation of the retrieved document.

Description

Retrieves a single document from a MongoDB collection by ID.

Example

dim id as c = "10051164"
dim pr as p
pr = mongo_getDocument("mongoAtlas", "sample_airbnb", "listingsAndReviews", id, "room_type,bed_type")

if pr.error = .f. then
    showvar(pr.result)
end if

See Also