I가 MongoDB의에서 다음 쿼리 - 모든이 주위에 내 머리를 정리 할 수 몽고 집계 쿼리
db.devices.aggregate({
$match: {userId: "v73TuQqZykbxFXsWo", state: true}},
{
$project: {
userId: 1,
categorySlug: 1,
weight: {
$cond: [
{"$or": [
{$eq: ["$categorySlug", "air_fryer"] },
{$eq: ["$categorySlug", "iron"] }
] },
0, 1] }
} },
{$sort: {weight: 1}},
{ $limit : 10 }
);
내가 산화 마그네슘 드라이버를 사용 golang이 쓰기 위해 노력하고있어
하지만 !
어떻게 이것을 golang mgo 쿼리로 변환합니까?
그냥 따옴표, 같은 것을 사용하여 쿼리의 각 둥지 수준의 주위에 포장 각 단계와 use'bson.M을 {}'분할' match : = bson.M { "$ match": bson.M { "userId": "...", ...}}','project : = bson.M { "$ project" '. 이제'pipe : = collection.Pipe ([] bson.M {match, project})'와 같이 그것들과 함께 mgo 드라이버'Pipe'를 사용하고, 마지막으로'pipe.All (& yourResultStruct)'로 결과를 검색합니다. 'Pipe'의 문서보기 [여기] (https://godoc.org/labix.org/v2/mgo#Collection.Pipe) – Anzel