diff --git a/src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs b/src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs index 89adae69..149cb18b 100644 --- a/src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs +++ b/src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs @@ -624,11 +624,23 @@ private Dictionary LcmWsToLfWs() return lfWsList; } - private ConvertLcmToMongoOptionList ConvertOptionListFromLcm(ILfProject project, string listCode, ICmPossibilityList LcmOptionList, bool updateMongoList = true) + private ConvertLcmToMongoOptionList ConvertOptionListFromLcm(ILfProject project, string listCode, ICmPossibilityList lcmOptionList, bool updateMongoList = true) { - LfOptionList lfExistingOptionList = Connection.GetLfOptionListByCode(project, listCode); + LfOptionList lfExistingOptionList = null; + try + { + lfExistingOptionList = Connection.GetLfOptionListByCode(project, listCode); //doesn't work unless the DB is fully populated + } + catch (Exception) { } + var converter = new ConvertLcmToMongoOptionList(lfExistingOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory); - LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(LcmOptionList); + LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(lcmOptionList); + + if (lfExistingOptionList == null) + { + lfChangedOptionList.DateModified = lcmOptionList.DateModified; //if DB didn't have an entry, preserve LCM date + } + if (updateMongoList) Connection.UpdateRecord(project, lfChangedOptionList, listCode); return new ConvertLcmToMongoOptionList(lfChangedOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory); diff --git a/src/LfMerge.Core/MongoConnector/MongoConnection.cs b/src/LfMerge.Core/MongoConnector/MongoConnection.cs index f9616bca..b8d88754 100644 --- a/src/LfMerge.Core/MongoConnector/MongoConnection.cs +++ b/src/LfMerge.Core/MongoConnector/MongoConnection.cs @@ -970,10 +970,10 @@ private bool UpdateRecordImpl(ILfProject project, TDocument data, Fil mongoDb = GetMainDatabase(); UpdateDefinition update = BuildUpdate(data, false); IMongoCollection collection = mongoDb.GetCollection(collectionName); - var updateOptions = new FindOneAndUpdateOptions { + var updateOptions = new UpdateOptions { IsUpsert = true }; - collection.FindOneAndUpdate(filter, update, updateOptions); + collection.UpdateOne(filter, update, updateOptions); return true; }