Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.1
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
Statistic
FMM
Blog
Inserts a document into collection.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
MongoDB | 12.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example | Flags |
---|---|---|---|
MongoDBRef | The reference number for the mongo connection. | $MongoDB | |
documentJSON | The JSON with the record to save. | ||
OptionsJSON | The options to use. | Optional |
Returns JSON or error.
Number | Subtype |
0 | Generic binary subtype |
1 | Function data |
2 | Binary (old) |
3 | UUID (old) |
4 | UUID |
5 | MD5 |
6 | Encrypted BSON value |
7 | Compressed time series data |
Insert a Record:
# 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) ]
# open the database
Set Variable [ $r ; Value: MBS( "MongoDB.OpenDatabase"; $Mongo; "local" ) ]
# open the collection (table)
Set Variable [ $r ; Value: MBS( "MongoDB.OpenCollection"; $Mongo; "test" ) ]
# now insert a record with passing a JSON
Set Variable [ $r ; Value: MBS( "MongoDB.InsertOne"; $Mongo; "{\"Hello\": \"FileMaker\"}" ) ]
# and show answer/error
Show Custom Dialog [ "Insert Reply" ; $r ]
# cleanup
Set Variable [ $r ; Value: MBS( "MongoDB.Release"; $Mongo ) ]
Insert an image as binary data:
Set Variable [ $data ; Value: JSONSetElement ( "{}" ; ["subType"; 0; JSONString]; ["base64"; Base64Encode ( test::Image ); JSONString]) ]
Set Variable [ $binary ; Value: JSONSetElement ( "{}" ; ["$binary"; $data; JSONRaw]) ]
Set Variable [ $json ; Value: JSONSetElement ( "{}" ; ["FileID" ; 123 ; JSONNumber] ; ["filename" ; "test.png" ; JSONString] ; ["Data" ; $binary ; JSONRaw] ) ]
# JSON like this: {"Data":{"$binary":{"base64":"iVBORw0K...ElFTkSuQmCC\r\n","subType":0}},"FileID":123,"filename":"test.png"}
# show in field
Set Field [ test::Insert JSON ; $json ]
# and insert to database
Set Variable [ $r ; Value: MBS( "MongoDB.InsertOne"; $Mongo; $json) ]
Show Custom Dialog [ "Result" ; $r ]
This function checks for a license.
Created 22nd May 2022, last changed 29th August 2022