I'm using the mongo-go-driver (https://godoc.org/github.com/mongodb/mongo-go-driver/mongo) and I'm trying to do the equivalent of
db.getCollection('mycollection').aggregate([
{ $lookup: {
from: "anothercollection",
localField: "_id",
foreignField: "foreignID",
as: "matched_docs"
}},
{ $match: { "matched_docs": { $eq: [] } } },
{ $project: { "matched_docs": 0 } },
{ $match: {"dateTimeGMT":{$lt: (new Date(Date.now()-1000*60*60*24)).toISOString()}} }
])
I can't figure out how to put the Javascript commands in using this method.
pipeline := bson.NewArray(
bson.VC.DocumentFromElements(
bson.EC.SubDocumentFromElements(
//yada, yada, yada...
cursor, err := collection.Aggregate(ctx, pipeline)
(In general, I dislike this method, anyway. I want to be able to design queries in Robo 3T and copy them to my code just like I do with MySQL Workbench and PHP)
This method yields an empty *bson.Array in pipeline
pipelineJSON := `[
{ $lookup: {
from: "anothercollection",
localField: "_id",
foreignField: "interactionID",
as: "matched_docs"
}},
{ $match: { "matched_docs": { $eq: [] } } },
{ $project: { "matched_docs": 0 } },
{ $match: {"dateTimeGMT":{$lt: (new Date(Date.now()-1000*60*60*24)).toISOString()}} }
]`
pipeline, err = bson.ParseExtJSONArray(pipelineJSON)
I'd really love it if there were a way to send Mongo a command as a string (like I was typing it into Robo 3T) and get a *mongo.Cursor back. Is there a better driver (that is still supported by someone) that I should use instead? Do I need to code my own?
Thanks!