-
Type: Bug
-
Resolution: Fixed
-
Priority: Blocker - P1
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
Not Needed
-
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
- is related to
-
SERVER-81614 Projection form of $slice only works with find, not with $project
- Closed