@@ -348,31 +348,41 @@ func transformValue(registry *bsoncodec.Registry, val interface{}) (bsoncore.Val
348
348
}
349
349
350
350
// Build the aggregation pipeline for the CountDocument command.
351
- func countDocumentsAggregatePipeline (registry * bsoncodec.Registry , filter interface {}, opts * options.CountOptions ) (bsonx.Arr , error ) {
352
- pipeline := bsonx.Arr {}
353
- filterDoc , err := transformDocument (registry , filter )
354
-
351
+ func countDocumentsAggregatePipeline (registry * bsoncodec.Registry , filter interface {}, opts * options.CountOptions ) (bsoncore.Document , error ) {
352
+ filterDoc , err := transformBsoncoreDocument (registry , filter )
355
353
if err != nil {
356
354
return nil , err
357
355
}
358
- pipeline = append (pipeline , bsonx .Document (bsonx.Doc {{"$match" , bsonx .Document (filterDoc )}}))
359
356
357
+ aidx , arr := bsoncore .AppendArrayStart (nil )
358
+ didx , arr := bsoncore .AppendDocumentElementStart (arr , strconv .Itoa (0 ))
359
+ arr = bsoncore .AppendDocumentElement (arr , "$match" , filterDoc )
360
+ arr , _ = bsoncore .AppendDocumentEnd (arr , didx )
361
+
362
+ index := 1
360
363
if opts != nil {
361
364
if opts .Skip != nil {
362
- pipeline = append (pipeline , bsonx .Document (bsonx.Doc {{"$skip" , bsonx .Int64 (* opts .Skip )}}))
365
+ didx , arr = bsoncore .AppendDocumentElementStart (arr , strconv .Itoa (index ))
366
+ arr = bsoncore .AppendInt64Element (arr , "$skip" , * opts .Skip )
367
+ arr , _ = bsoncore .AppendDocumentEnd (arr , didx )
368
+ index ++
363
369
}
364
370
if opts .Limit != nil {
365
- pipeline = append (pipeline , bsonx .Document (bsonx.Doc {{"$limit" , bsonx .Int64 (* opts .Limit )}}))
371
+ didx , arr = bsoncore .AppendDocumentElementStart (arr , strconv .Itoa (index ))
372
+ arr = bsoncore .AppendInt64Element (arr , "$limit" , * opts .Limit )
373
+ arr , _ = bsoncore .AppendDocumentEnd (arr , didx )
374
+ index ++
366
375
}
367
376
}
368
377
369
- pipeline = append (pipeline , bsonx .Document (bsonx.Doc {
370
- {"$group" , bsonx .Document (bsonx.Doc {
371
- {"_id" , bsonx .Int32 (1 )},
372
- {"n" , bsonx .Document (bsonx.Doc {{"$sum" , bsonx .Int32 (1 )}})},
373
- })},
374
- },
375
- ))
378
+ didx , arr = bsoncore .AppendDocumentElementStart (arr , strconv .Itoa (index ))
379
+ iidx , arr := bsoncore .AppendDocumentElementStart (arr , "$group" )
380
+ arr = bsoncore .AppendInt32Element (arr , "_id" , 1 )
381
+ iiidx , arr := bsoncore .AppendDocumentElementStart (arr , "n" )
382
+ arr = bsoncore .AppendInt32Element (arr , "$sum" , 1 )
383
+ arr , _ = bsoncore .AppendDocumentEnd (arr , iiidx )
384
+ arr , _ = bsoncore .AppendDocumentEnd (arr , iidx )
385
+ arr , _ = bsoncore .AppendDocumentEnd (arr , didx )
376
386
377
- return pipeline , nil
387
+ return bsoncore . AppendArrayEnd ( arr , aidx )
378
388
}
0 commit comments