From 5a27adf0342709ab9e941e827eb07c068f64633a Mon Sep 17 00:00:00 2001 From: hz Date: Mon, 9 Jun 2025 19:53:04 -0500 Subject: [PATCH] Fixing 500 for real for real --- Services/LocationService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Services/LocationService.cs b/Services/LocationService.cs index 730b996..017203d 100644 --- a/Services/LocationService.cs +++ b/Services/LocationService.cs @@ -64,7 +64,8 @@ public class LocationService var idFilter = Builders.Filter.Eq(l => l.Id, locationId); // if the Content array is null, initialize it first - var nullFilter = idFilter & Builders.Filter.Eq("Content", BsonNull.Value); + // use a raw BsonDocument filter to avoid casting BsonNull to an ObjectId + var nullFilter = idFilter & new BsonDocument("Content", BsonNull.Value); var initArray = Builders.Update.Set(l => l.Content, new List()); await _locations.UpdateOneAsync(nullFilter, initArray); @@ -77,7 +78,8 @@ public class LocationService if (!ObjectId.TryParse(locationId, out _) || !ObjectId.TryParse(itemId, out _)) return; - var filter = Builders.Filter.Eq(l => l.Id, locationId) & Builders.Filter.Ne("Content", BsonNull.Value); + // check that the Content array exists by using a raw BsonDocument filter + var filter = Builders.Filter.Eq(l => l.Id, locationId) & new BsonDocument("Content", new BsonDocument("$ne", BsonNull.Value)); var update = Builders.Update.Pull(l => l.Content, itemId); await _locations.UpdateOneAsync(filter, update); }