Skip to content

Conversation

Copy link

Copilot AI commented Nov 5, 2025

MongoDB queries fail with "BSONObj size invalid" error when groups contain thousands of members (~20k), hitting the 16MB BSON limit on aggregate commands.

Status

Fix already implemented in v6.0.6 - no changes required. This PR verifies the fix is present and working.

Implementation (Existing)

The FindSCIMRepresentations method in SCIMRepresentationQueryRepository.cs now uses a two-query approach instead of a MongoDB join:

// Fetch representations first
var representationsList = await filteredRepresentations.ToListAsync(cancellationToken);
var representationIds = representationsList.Select(r => r.Id).ToList();

// Separate attribute query with simple WHERE IN
var attributes = await _scimDbContext.SCIMRepresentationAttributeLst.AsQueryable()
    .Where(a => representationIds.Contains(a.RepresentationId))
    .ToListAsync(cancellationToken);

// Group and combine in-memory
var attributesByRepId = attributes.GroupBy(a => a.RepresentationId)
    .ToDictionary(g => g.Key, g => g.ToList());

This avoids MongoDB aggregate commands entirely, eliminating the BSON size constraint.

Verification

  • MongoDB persistence project builds successfully
  • All 7 SCIM unit tests pass
  • Acceptance tests cover group operations extensively
Original prompt

This section details on the original issue you should resolve

<issue_title>[SCIM] Get group error "Size must be between 0 and 16793600(16MB)"</issue_title>
<issue_description>Hello guys,

we have this issue when the group has thousands of users inside:

Groups?filter=displayName+eq+"GLOBAL-READ"

The error is:
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:Error"
],
"status": "500",
"scimType": "internalServerError",
"detail": "Command aggregate failed: PlanExecutor error during aggregation :: caused by :: BSONObj size: 76105902 (0x48948AE) is invalid. Size must be between 0 and 16793600(16MB) First element: Representation: { _id: "876c7a69-d1be-4e05-aa65-d8406f0bda79", _t: [ "SCIMRepresentation", "SCIMRepresentationModel" ], ExternalId: null, ResourceType: "Group", Version: 6731, DisplayName: "GLOBAL-READ", RealmName: "", Created: new Date(1752069237447), LastModified: new Date(1753778133279), SchemaRefs: [ { $ref: "scimSchemas", $id: "urn:ietf:params:scim:schemas:core:2.0:Group" } ], AttributeRefs: null }."
}

This Group has around 20,000 members.

Can you please check?

Regards.
Gabriele</issue_description>

Comments on the Issue (you are @copilot in this section)

@simpleidserver Hello,

There is indeed an issue in the FindSCIMRepresentations function in the SCIMRepresentationQueryRepository class.
When a group contains a large number of attributes, the following query throws an exception. The LINQ query is translated into a MongoDB aggregate command, and the resulting data size exceeds 16 MB.

var filteredRepresentationsWithAttributes = from a in filteredRepresentations
                                            join b in _scimDbContext.SCIMRepresentationAttributeLst.AsQueryable() on a.Id equals b.RepresentationId into Attributes
                                            select new
                                            {
                                                Representation = a,
                                                Attributes = Attributes
                                            };
											

This issue should be fixed in the release/v6.0.4 branch. Could you please try again and confirm?

KR,

SID


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix SCIM group error for large user lists [SCIM] Verify MongoDB fix for large group BSON size limit error Nov 5, 2025
Copilot AI requested a review from simpleidserver November 5, 2025 16:28
@simpleidserver simpleidserver requested review from Copilot and removed request for Copilot and simpleidserver November 5, 2025 17:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SCIM] Get group error "Size must be between 0 and 16793600(16MB)"

2 participants