globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 231 forks source link

pipe All returns empty array #316

Closed AhmedX6 closed 5 years ago

AhmedX6 commented 5 years ago

What version of MongoDB are you using (mongod --version)?

db version v3.6.2
git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: 2008plus-ssl
    distarch: x86_64
    target_arch: x86_64

What version of Go are you using (go version)?

go version go1.9.3 windows/amd64

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Home\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Home\AppData\Local\Temp\go-build477425875=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

What did you do?

I'm trying to retrieve a nested array ("messages") on a document in my collection, here is a json example of my collection

"messages" : 
{
    "_id" : ObjectId("5c26844696b72e4b6c9ceee7"),
    "pointer" : ObjectId("5c26844696b72e4b6c9ceee6"),
    "messages" : [ 
        {
            "uuid" : "f03f7977-0b4e-11e9-9f95-144fd7c03810",
            "content" : "Hello"
        }, 
        {
            "uuid" : "78bb831d-0b57-11e9-a286-144fd7c03810",
            "content" : "ouiii"
        }
    ]
}

Here is my pipeline in golang :

pipeTask := []bson.M{{"$match": bson.M{"pointer": pointer}}, {"$unwind": "$messages"},
        {"$limit": 100}, {"$project": bson.M{"content": "$messages.content", "uuid": "$messages.uuid"}}}

When I execute it, got a empty array. What is the problem ? Thanks for help... This code was working using mgo of LABIX.

Can you reproduce the issue on the latest development branch?

Yes

domodwyer commented 5 years ago

Hi @AhmedX6

Can you put together a runnable example? I don't believe we've made any significant changes to Pipe compared to the original mgo.

Dom

l2eady commented 5 years ago

Hi @AhmedX6 I think the reason that you got empty array is because the $match command that you want to match is wrong value can you try with match": bson.M{"pointer": ObjectId("5c26844696b72e4b6c9ceee6")}}

eminano commented 5 years ago

Thanks @l2eady!

@AhmedX6, did the solution proposed work? If so, we'll close this issue.

Thanks! Esther

AhmedX6 commented 5 years ago

Hello,

No it did not work I used an other library sorry for late response you can close this issue.

Thanks, Ahmed

eminano commented 5 years ago

Sorry to hear, thanks for your response!

heipacker commented 4 years ago

it is this problem have a soluation? i still have this problem, pipe all return empty array

heipacker commented 4 years ago

@eminano @AhmedX6 which library did you use?

AhmedX6 commented 4 years ago

@heipacker I used https://godoc.org/gopkg.in/mgo.v2