protected long UpdateAll(QueryOptions options, IMongoUpdate update, bool sendNotifications = true) { var result = _collection.Update(options.GetMongoQuery(_getIdValue), update, UpdateFlags.Multi); if (!sendNotifications || !EnableNotifications || _messagePublisher == null) { return(result.DocumentsAffected); } if (options.OrganizationIds.Any()) { foreach (var orgId in options.OrganizationIds) { PublishMessage(new EntityChanged { ChangeType = ChangeType.UpdatedAll, OrganizationId = orgId, Type = _entityType }); } } else { PublishMessage(new EntityChanged { ChangeType = ChangeType.UpdatedAll, Type = _entityType }); } return(result.DocumentsAffected); }
protected long RemoveAll(QueryOptions options, bool sendNotifications = true) { if (options == null) { throw new ArgumentNullException("options"); } var fields = new List <string>(new[] { CommonFieldNames.Id }); if (_isOwnedByOrganization) { fields.Add(CommonFieldNames.OrganizationId); } if (_isOwnedByProject) { fields.Add(CommonFieldNames.ProjectId); } if (_isOwnedByStack) { fields.Add(CommonFieldNames.StackId); } if (_isUser) { fields.AddRange(new [] { "OrganizationIds", "EmailAddress" }); } long recordsAffected = 0; var documents = Collection.FindAs <T>(options.GetMongoQuery(_getIdValue)) .SetLimit(Settings.Current.BulkBatchSize) .SetFields(fields.ToArray()) .ToList(); while (documents.Count > 0) { recordsAffected += documents.Count; Remove(documents, sendNotifications); documents = Collection.FindAs <T>(options.GetMongoQuery(_getIdValue)) .SetLimit(Settings.Current.BulkBatchSize) .SetFields(fields.ToArray()) .ToList(); } return(recordsAffected); }
protected long RemoveAll(QueryOptions options, bool sendNotifications = true) { if (options == null) { throw new ArgumentNullException("options"); } var fields = new List <string>(new[] { CommonFieldNames.Id }); if (_isOwnedByOrganization) { fields.Add(CommonFieldNames.OrganizationId); } if (_isOwnedByProject) { fields.Add(CommonFieldNames.ProjectId); } if (_isOwnedByStack) { fields.Add(CommonFieldNames.StackId); } long recordsAffected = 0; var documents = Collection.FindAs <T>(options.GetMongoQuery(_getIdValue)) .SetLimit(RepositoryConstants.BATCH_SIZE) .SetFields(fields.ToArray()) .ToList(); while (documents.Count > 0) { recordsAffected += documents.Count; Remove(documents, sendNotifications); documents = Collection.FindAs <T>(options.GetMongoQuery(_getIdValue)) .SetLimit(RepositoryConstants.BATCH_SIZE) .SetFields(fields.ToArray()) .ToList(); } return(recordsAffected); }