Xbasic

mongo_updateDocument Function

Syntax

P result = mongo_updateDocument(C mongoURL_or_connectionString, C databaseName, C collection, C id, C json [, C mode])

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 containing the document.

idCharacter

The ID of the document to update.

jsonCharacter

The JSON data containing the updates.

modeCharacter

Default = "add". The update mode.

add

Properties in the specified JSON are added/updated in the existing document. No existing properties are removed.

replace

The specified JSON completely replaces the existing document.

Returns

resultPointer

Returns an object with error (.t./.f.) and errorText properties.

Description

Updates an existing document in a MongoDB collection.

Example

dim id as c = "60773000296c0832586538ba"
dim p as p
p.firstName = "Fred"
p.lastName = "Jones" 'Updating last name

dim json as c 
json = json_generate(p)

dim pr as p
' Update specific fields ("add" mode)
pr = mongo_updateDocument("::name::my_mongo_connString", "myDatabase", "newCollection", id, json, "add")

See Also