[GODRIVER-679] Aggregate does not accept a bson.A as the pipeline Created: 07/Dec/18  Updated: 28/Oct/23  Resolved: 19/Dec/18

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: 0.1.0
Fix Version/s: 0.2.0

Type: Bug Priority: Major - P3
Reporter: PJ Tatlow Assignee: Kristofer Brandow (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

It seems like you should be able to use a bson.A to hold several bson.D or bson.M documents to create an aggregation pipeline. But when I try I get the error "cannot transform type primitive.A to a *bsonx.Document".

Example:

pipeline := bson.A{
		bson.M{"$match": bson.M{"userID": userID}},
		bson.M{"$sort": bson.M{"date": -1}},
		bson.M{"$limit": defaultLimit},
                // other steps
}
_, err := collection.Aggregate(context.Background(), pipeline)
err.Error() == "cannot transform type primitive.A to a *bsonx.Document"



 Comments   
Comment by Githook User [ 19/Dec/18 ]

Author:

{'username': 'skriptble', 'email': 'kris@mongodb.com', 'name': 'Kris Brandow'}

Message: Fix transforming of interface{} into agg pipeline

This commit fixes the transformAggregatePipeline function, which
previously didn't properly handle arrays and slices. The function now
does not accept a document, instead requiring either a slice, array, or
a type that implements ValueMarshaler and returns a BSON array from its
MarshalBSONValue method.

GODRIVER-679

Change-Id: I5f1e4b6fe84a6e1db6dda187010d7f94e4a42e7b
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/17bb285b0e7483ebd3afb691580630d2e08ee1c3

Comment by Kristofer Brandow (Inactive) [ 12/Dec/18 ]

Code Review: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/437017.

Comment by Ad [ 09/Dec/18 ]

Following this issue. Having the problem in buiding an aggregation pipeline. 

Generated at Thu Feb 08 08:34:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.