On Wednesday, November 14, 2012 1:25:20 PM UTC-5, Stephen Lee wrote:
> Judging from the C++ source of the BSON implementation in MongoDB, I'd
> guess that the 'exception: wrong type for field (pipeline) 3 != 4' refers
> to the parser expecting either an Object (type == 3) and got an Array (type
> == 4) or the other way around.
> Which line of your Perl script throws the error? If it's the "print
> Dumper(\@pipeline)" line, could you try "print Dumper-ing" just the
> $project and $group individually? I'm guessing that your Mongo shell JSON
> to Perl translation might have an error, but after a quick glance, I don't
> quite see it.
> On Tuesday, November 13, 2012 5:03:20 PM UTC-5, Chris Matta wrote:
>> Sorry, documents look like this:
>> {
>> "_id" : ObjectId("5097ffa800ba62343500f7ec"),
>> "adaptor_id" : "DKA-2NL",
>> "processor_id" : NumberLong(5),
>> "datetime" : ISODate("2012-11-05T17:25:00Z"),
>> "array_serial" : NumberLong(12345),
>> "metric" : 26.989082,
>> "processor_type" : "DKP"
>> }
>> On Tuesday, November 13, 2012 4:58:21 PM UTC-5, Chris Matta wrote:
>>> I'm trying to implement an aggregation function I've gotten to
>>> successfully work in javascript in perl, but I keep getting the error
>>> 'exception: wrong type for field (pipeline) 3 != 4'. Any ideas where I
>>> could be going wrong?
>>> my $project = Tie::IxHash->new(
>>> "year" => { '$year' => '$datetime'},
>>> "month" => {'$month' => '$datetime'},
>>> "day" => {'$dayOfMonth' => '$datetime'},
>>> "hour" => { '$hour' => '$datetime'},
>>> # the minute field is being rounded down to the
>>> nearest resolution
>>> "minute" => {'$subtract' => (
>>> {'$minute' => '$datetime'},
>>> {'$mod' => ({'$minute' =>
>>> '$datetime'}, $resolution)}
>>> )},
>>> array_serial => 1,
>>> adaptor_id => 1,
>>> processor_id => 1,
>>> processor_type => 1,
>>> metric => 1
>>> );
>>> my $group = Tie::IxHash->new(
>>> _id => { array_serial => '$array_serial',
>>> adaptor_id => '$adaptor_id',
>>> processor_id => '$processor_id',
>>> processor_type => '$processor_type',
>>> year => '$year',
>>> month => '$month',
>>> day => '$day',
>>> hour => '$hour',
>>> minute => '$minute'
>>> },
>>> metric => {
>>> '$avg' => '$metric'
>>> }
>>> );
>>> my @pipeline = (
>>> {'$match' => $query},
>>> {'$project' => $project},
>>> { '$group' => $group }
>>> );
>>> print Dumper(\@pipeline);
>>> my $aggregateCommand = Tie::IxHash->new(aggregate => $collection,
>>> pipeline => @pipeline);
>>> my $result = $db->run_command($aggregateCommand);
>>> print Dumper($result);