Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
MongoDB.Connect
Connects the client using the URI provided.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
MongoDB | 12.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
MongoDBRef | The reference number for the mongo connection. | $MongoDB | |
DoPing | Available in MBS FileMaker Plugin 13.4 or newer. Whether to ping server and make a connection. Default is 1 to enable. |
1 | Optional |
Result
Returns OK or error.
Description
Connects the client using the URI provided.See connection string examples in MongoDB.SetURI function.
Examples
Connect:
# start a new session
Set Variable [ $Mongo ; Value: MBS( "MongoDB.New" ) ]
# where is the server?
Set Variable [ $r ; Value: MBS( "MongoDB.SetURI"; $Mongo; "mongodb://localhost/" ) ]
# connect
Set Variable [ $r ; Value: MBS( "MongoDB.Connect"; $Mongo) ]
#
# now do something
#
# cleanup
Set Variable [ $r ; Value: MBS( "MongoDB.Release"; $Mongo ) ]
Run SSH Tunnel to connect to MongoDB:
# some settings like local IP/Port
Set Variable [ $LocalIP ; Value: "127.0.0.1" ]
Set Variable [ $LocalPort ; Value: 12345 ]
# the SSH server to connect through
Set Variable [ $SSHServerIP ; Value: "myserver.test" ]
# database to connect
Set Variable [ $DatabaseIP ; Value: "db.myserver.test" ]
Set Variable [ $DatabasePort ; Value: 27017 ]
# create connection
Set Variable [ $ssh ; Value: MBS( "SSH.New" ) ]
Set Variable [ $r ; Value: MBS( "SSH.Connect"; $ssh; $SSHServerIP ) ]
Set Variable [ $r ; Value: MBS( "SSH.SessionHandshake"; $ssh) ]
# using private key file here, but username+password is also possible
Set Variable [ $r ; Value: MBS( "SSH.UserAuthPublicKeyFile"; $ssh; "username"; "" ; $keypair_path ; "password" ) ]
Set Variable [ $auth ; Value: MBS( "SSH.IsAuthenticated"; $ssh ) ]
# must be 1
Set Variable [ $r ; Value: MBS( "SSH.Tunnel.Run"; $ssh; $DatabaseIP; $DatabasePort; $LocalIP; $LocalPort) ]
Pause/Resume Script [ Duration (seconds): .5 ]
Set Variable [ $tunnel_mess ; Value: MBS( "SSH.Tunnel.Messages"; $ssh ) ]
# now this should show that tunnel is waiting.
Set Variable [ $MongoDB ; Value: MBS("MongoDB.New") ]
Set Variable [ $r ; Value: MBS("MongoDB.SetURI"; $MongoDB; "mongodb://" & $LocalIP & ":" & $DatabasePort & "/") ]
Set Variable [ $r ; Value: MBS("MongoDB.Connect"; $MongoDB) ]
Set Variable [ $tunnel_mess ; Value: MBS( "SSH.Tunnel.Messages"; $ssh ) ]
Show Custom Dialog [ $tunnel_mess & ¶ & $r ]
# should show OK for connect and for tunnel that it's forwarding data
# do query here
Set Variable [ $list ; Value: MBS( "MongoDB.DatabasesNames"; $MongoDB ) ]
Show Custom Dialog [ "Databases" ; $list ]
# disconnect
Set Variable [ $r ; Value: MBS("SQL.Release"; $MongoDB) ]
Set Variable [ $r ; Value: MBS( "SSH.Tunnel.Cancel"; $ssh ) ]
Pause/Resume Script [ Duration (seconds): .1 ]
Set Variable [ $r ; Value: MBS( "SSH.Disconnect"; $ssh ) ]
Set Variable [ $r ; Value: MBS( "SSH.Release"; $ssh ) ]
See also
- MongoDB.UpdateMany
- MongoDB.UpdateOne
- SSH.Connect
- SSH.Disconnect
- SSH.IsAuthenticated
- SSH.New
- SSH.Tunnel.Cancel
- SSH.Tunnel.Messages
- SSH.Tunnel.Run
- SSH.UserAuthPublicKeyFile
Example Databases
Blog Entries
- News in MBS FileMaker Plugin 13.4
- OnWindowTransaction and MongoDB
- FileMaker and MongoDB
- New MongoDB Example
- MBS FileMaker Plugin, version 12.3pr5
This function checks for a license.
Created 22nd May 2022, last changed 23th June 2024