public async Task <bool> Link(IImmutableSet <string> userIds) { List <LinkedAccount> linkedAccountEntries = await _collection // .Find(l => l.UserIds.Intersect(userIds).Any()) .Find(Builders <LinkedAccount> .Filter.AnyIn(l => l.UserIds, userIds)) .ToListAsync(); ImmutableHashSet <string> existingUserIds = linkedAccountEntries .SelectMany(l => l.UserIds) .ToImmutableHashSet(); ImmutableHashSet <string> allUserIds = existingUserIds.Union(userIds); if (existingUserIds.Count == allUserIds.Count) { return(false); // already marked as linked } // don't bother patching existing documents, just delete all old ones and make a new one await _collection.InsertOneAsync(new LinkedAccount(string.Empty, allUserIds.ToHashSet())); foreach ((string id, _) in linkedAccountEntries) { await _collection.DeleteOneAsync(l => l.Id == id); } return(true); }
public DataNode Write(ISerializationManager serializationManager, ImmutableHashSet <T> value, bool alwaysWrite = false, ISerializationContext?context = null) { return(Write(serializationManager, value.ToHashSet(), alwaysWrite, context)); }