Extension::MongoDBCreate Method

Syntax

.Create as Extension::MongoDB (baseURI as C, database as C, collection as C)

Arguments

baseURI

The mongoDb server

database

The Database on the mongoDb server

collection

The Collection in the Database on the mongoDb server

Description

Create a mongo object.

Just The Server URL

dim mongo as extension::MongoDB = extension::MongoDB::Create("mongodb://localhost:27017")

dim databasesJson as c = mongo.ListDatabases()
dim def as p = json_parse(databasesJson)

? def.databases[1]
= empty = .F.
name = "TestDatabase"
sizeOnDisk = 73728

You can supply just the mongo server URL if you are interested in Database discovery, and don't need to update a collection.

Just The Server URL and Database

dim mongo as extension::MongoDB = extension::MongoDB::Create("mongodb://localhost:27017","TestDatabase")

dim mongo as extension::MongoDB = extension::MongoDB::Create("mongodb://localhost:27017","TestDatabase")
? mongo.ListCollections()
= ["flowers"]

You can supply just the mongo server URL and the database if you are interested in listing collections available and other database level operations.

URL Database and Collection

dim mongo as extension::MongoDB = extension::MongoDB::Create("mongodb://localhost:27017","TestDatabase","flowers")
dim json as c = mongo.GetRecords("")
dim def as p = json_parse(json)
? def[1]
= _id = "6065f82cdbef84456ce731dd"
Id = "00000062"
Imagedate = "08/12/2001"
Keywords = "rudbekia daisy yellow"
Picture = =filename_decode("Hires\rudbekia.jpg")

Finally, if you are going to use collection methods like GetRecords, you will need to supply the collection.

Sometimes You will need to set the Certificate property

dim mongo as  extension::MongoDB = extension::MongoDB::Create("mongodb+srv://<username>:<password>@cluster0.7klge.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
mongo.certificate = "none"
? mongo.ListDatabases()
= {"databases":[{"name":"sample_airbnb","sizeOnDisk":54632448,"empty":false},{"name":"sample_analytics","sizeOnDisk":9572352,"empty":false},{"name":"sample_geospatial","sizeOnDisk":1363968,"empty":false},{"name":"sample_mflix","sizeOnDisk":44462080,"empty":false},{"name":"sample_restaurants","sizeOnDisk":6737920,"empty":false},{"name":"sample_supplies","sizeOnDisk":1142784,"empty":false},{"name":"sample_training","sizeOnDisk":49123328,"empty":false},{"name":"sample_weatherdata","sizeOnDisk":2826240,"empty":false},{"name":"admin","sizeOnDisk":327680,"empty":false},{"name":"local","sizeOnDisk":4606025728,"empty":false}],"totalSize":4776214528,"ok":1,"$clusterTime":{"clusterTime":"6946237383616495620","signature":{"hash":"hm1ntWRg7jBUITyS6ZFkgkdvTDI=","keyId":"6931688929225605123"}},"operationTime":"6946237383616495620"}

Not settable in the Create method, some servers require you set (or ommit) the certificate file.

The Default behaviour is to include the alpha anywhere caroot certificate, you can supply it with your own certificate, or omit the certificate by setting this to 'none'.