我正在使用 mongo-go-driver ( https://godoc.org/github.com/mongodb/mongo-go-driver/mongo ),我正在尝试做相当于
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()}} }
])
我不知道如何使用这种方法放置 Javascript 命令。
pipeline := bson.NewArray(
bson.VC.DocumentFromElements(
bson.EC.SubDocumentFromElements(
//yada, yada, yada...
cursor, err := collection.Aggregate(ctx, pipeline)
(总的来说,无论如何,我不喜欢这种方法。我希望能够在 Robo 3T 中设计查询并将它们复制到我的代码中,就像我使用 MySQL Workbench 和 PHP 一样)
此方法在管道中产生一个空的 *bson.Array
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)
如果有一种方法可以将 Mongo 的命令作为字符串发送(就像我在 Robo 3T 中键入它一样)并获得 *mongo.Cursor ,我真的很喜欢它。我应该使用更好的驱动程序(仍然有人支持)吗?我需要自己编码吗?
谢谢!