Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with the following pipeline and dataset #21

Open
javaknight opened this issue Jul 10, 2015 · 4 comments
Open

Doesn't work with the following pipeline and dataset #21

javaknight opened this issue Jul 10, 2015 · 4 comments

Comments

@javaknight
Copy link

In Meteor:

        var pipeline = [
            {$match: { "shipperZip.start" : {$lte: '07621'},
                       "shipperZip.end"   : {$gte: '07621'}}},
            {$unwind : "$recipientZip"},
            {$match: {"recipientZip.start": {$lte: '90011'},
                      "recipientZip.end":   {$gte: '90011'}}},
            {$project: {"recipientZip.expressZone": 1,
                        "recipientZip.groundZone": 1}}
        ];
        var results = myCollection.aggregate(pipeline);
        console.log(results);

yields
empty square brackets []
no data

In Mongo

db.sampleData.aggregate([{$match: {"shipperZip.start":{$lte: "07621"}, "shipperZip.end": {$gte: "07621"}}}, {$unwind: "$recipientZip"}, {$match: {"recipientZip.start": {$lte: "90011"}, "recipientZip.end": {$gte: "90011"}}}, {$project: {"recipientZip.expressZone": 1, "recipientZip.groundZone": 1}}])

yields:

{
"result" : [
{
"_id" : ObjectId("559ea710df8141168fb60ecd"),
"recipientZip" : {
"expressZone" : "8",
"groundZone" : "8"
}
}
],
"ok" : 1
}

Sample Collection (1 document):

{ 
    "_id" : ObjectId("559ea710df8141168fb60ecd"), 
    "shipperZip" : {
        "start" : "07000", 
        "end" : "07699", 
    }, 
    "recipientZip" : [ 
        {
            "start" : "90000", 
            "end" : "91000", 
            "expressZone" : "8", 
            "groundZone" : "8"
        },
    ]
}
@kluch
Copy link

kluch commented Nov 19, 2015

I have encountered the same issue.

It looks like according to my tests that it only runs the first match and then ignores the following match and group in this query:

var insertResultsAgg = WorkRequestItemCollection.aggregate(
  {$match : {wriType: {$in:["Type1", "Type2"]}}},
  {$unwind : "$wf"},
 {$match : {$or: [{"$wf.wfAssignedTo":{$in:["Jimmy"]}},{"$wf.wfFromUser":{$in:["Jimmy"]}}]}},
  {$group : {_id:"$_id"}}
);

@jedwards1211
Copy link

@ovidb
Copy link

ovidb commented Sep 12, 2016

@kluch in your case I think it should work if you wrap your pipeline in square brackets.

@SevenZark
Copy link

@ovidb Thanks for that! I was having the same problem and missed that small detail also (my pipeline was not actually wrapped in an array, but a series of comma-separated object literals -- I just forgot to wrap them in an array). This is a very easy mistake to make, since it will "fail" silently, since the comma-separated objects after the first one are just extra arguments to the function that will get ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants