Fixing 500 for real for real
This commit is contained in:
@@ -64,7 +64,8 @@ public class LocationService
|
||||
var idFilter = Builders<Location>.Filter.Eq(l => l.Id, locationId);
|
||||
|
||||
// if the Content array is null, initialize it first
|
||||
var nullFilter = idFilter & Builders<Location>.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<Location>.Update.Set(l => l.Content, new List<string>());
|
||||
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<Location>.Filter.Eq(l => l.Id, locationId) & Builders<Location>.Filter.Ne("Content", BsonNull.Value);
|
||||
// check that the Content array exists by using a raw BsonDocument filter
|
||||
var filter = Builders<Location>.Filter.Eq(l => l.Id, locationId) & new BsonDocument("Content", new BsonDocument("$ne", BsonNull.Value));
|
||||
var update = Builders<Location>.Update.Pull(l => l.Content, itemId);
|
||||
await _locations.UpdateOneAsync(filter, update);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user