Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4804

Slice projection must be rendered differently for Find and Aggregate

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 2.22.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      I have an mongo collection represented by C# class below:

       

      public sealed class SearchResultEntity : IEntity<string>, IQueriableByUserId
      {
          [BsonId]
          [BsonRepresentation(BsonType.ObjectId)]
          public string Id { get; set; }
          [BsonRequired]
          public long UserId { get; set; }
          [BsonRequired]
          public List<string> RealEstateCollection { get; set;}
      } 

      I'm trying to implement a function which paginates over RealEstateCollection and returns only those values that fall into specific range.

       

      For that I'm using Aggregate function and I'm constructing pipeline for that function:

       

      public PipelineDefinition<SearchResultEntity, SearchResultEntity> BuildGetResultsPageDefinition(long userId, int offset, int limit)
      {
          return PipelineDefinition<SearchResultEntity,SearchResultEntity>.Create(
              new IPipelineStageDefinition[]
              {                    
                  PipelineStageDefinitionBuilder.Match(BuildGetByUserIdDefinition(userId))
                  PipelineStageDefinitionBuilder.Project<SearchResultEntity, SearchResultEntity>(                           
                      Builders<SearchResultEntity>.Projection.Slice(nameof(SearchResultEntity.RealEstateCollection), offset, limit))
              });
      } 

      When I try to execute such query I end up with error below:
      MongoDB.Driver.MongoCommandException : Command aggregate failed: Failed to optimize pipeline :: caused by :: First argument to $slice must be an array, but is of type: int
       
      Mongo 6.0.6
      Running on localhost
      Driver version 2.19.0
       

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      How to Reproduce

      Use function and environment above to reproduce the problem

      Additional Background

      NA

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            eeasy.breezy@icloud.com Alex Gavrilov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: