In MongoDB I have a structure like:
$VAR1 = { 'score' => '26.5249035452273', 'student_id' => 177, '_id' => bless( { 'value' => 'something_unique' }, 'MongoDB::OID' ), 'type' => 'homework' };
BTW: yes this is homework

With a long list of documents (records) there are multiple documents per student_id and the first one appearing in the result-set needs to be removed.

I tried: $doc->delete_one( {'_id'=>$doc->{'MongoDB::OID'}} ) and get Can't call method "delete_one" on unblessed reference

I don't know where to go from here.
Thanks for your help.

Gert
use strict; use warnings; use MongoDB; my $client = MongoDB->connect(); my $db = $client->get_database('students'); my $coll = $db->get_collection('grades'); my $result = $coll->find( { 'type' => 'homework' } ) ->sort( [ ( 'student_id' => 1 ), ( 'score' => 1 ) ] ); #multipleSor +t my $previous = "1"; while ( my $doc = $result->next ) { # print $doc->{'student_id'} . " " . $doc->{'score'} . "\n"; # debug if ( $doc->{'student_id'} != $previous ) { # the following doesn't work.... # $doc->delete_one( {'_id'=>$doc->{'MongoDB::OID'}} ); $previous = $doc->{'student_id'}; } }

In reply to MongoDB removing document by GertMT

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.