We tested UniDAC for compatibility with MongoDB 4.0.2. UniDAC 7.3.9 does not support new capabilities yet, which appeared starting from the version MongoDB 4.0. Support for these features is still underway.
At the same time, UniDAC 7.3.9 supports all features of MongoDB 4.0.2, which are present in MongoDB 3.6.
To avoid the "Invalid namespace specified '.Session'" error, use MongoDB client libraries distributed with UniDAC. 32-bit libraries are located in the 'Bin\Win32\' subfolder relative to the folder where UniDAC was installed. 64-bit ones in the 'Bin\Win64\' subfolder. For example:
Code: Select all
UniConnection1.SpecificOptions.Values['MongoDB.BSONLibrary'] := 'C:\Program Files (x86)\Devart\UniDAC for RAD Studio XE4\Bin\Win32\libbson-1.0.dll';
UniConnection1.SpecificOptions.Values['MongoDB.ClientLibrary'] := 'C:\Program Files (x86)\Devart\UniDAC for RAD Studio XE4\Bin\Win32\libmongoc-1.0.dll';
UniConnection1.Connect;
To add a document to the collection, use the Database Command insert:
https://docs.mongodb.com/manual/referen ... nd/insert/ . For example:
Code: Select all
UniQuery1.SQL.Text := '{insert:"test", documents:[{"Id":"20180911190000","User":{"Id":784,"OfficeId":4,"CounterId":0,"WorkCityId":0}}]}';
UniQuery1.Execute;
To read this document from the collection, use the Database Command find:
https://docs.mongodb.com/manual/reference/command/find/ . For example:
Code: Select all
UniQuery1.SQL.Text := '{find:"test", filter:{Id:"20180911190000"}}';
UniQuery1.Open;