2.8. Eliminar documents
Vegem ara com podem eliminar un document de la col·lecció amb la funció remove().
Eliminem de la col·lecció el document amb el nom de gen uc001aaa.3
db.chr1.remove( { "name" : "uc001aaa.3"});
I comprovem si el document s’ha eliminat:
db.chr1.find().pretty();
> db.chr1.remove( { "name" : "uc001aaa.3"});
WriteResult({ "nRemoved" : 1 })
> db.chr1.find().pretty();
{
        "_id" : ObjectId("6487c410235597cf4bc92782"),
        "name" : "uc010nxr.1",
        "chrom" : "chr1",
        "strand" : "+",
        "txStart" : 11873,
        "txEnd" : 14409,
        "cdsStart" : 11873,
        "cdsEnd" : 11873,
        "exonCount" : 3,
        "exonStarts" : "11873,12645,13220,",
        "exonEnds" : "12227,12697,14409,",
        "proteinID" : "",
        "alignID" : "uc010nxr.1"
}
{
        "_id" : ObjectId("6487c41c235597cf4bc92783"),
        "name" : "uc009vit.3",
        "chrom" : "chr1",
        "strand" : "-",
        "txStart" : 14361,
        "txEnd" : 19759,
        "cdsStart" : 14361,
        "cdsEnd" : 14361,
        "exonCount" : 9,
        "exonStarts" : "14361,14969,15795,16606,16857,17232,17914,18267,18912,",
        "exonEnds" : "14829,15038,15947,16765,17055,17742,18061,18366,19759,",
        "proteinID" : "",
        "alignID" : "uc009vit.3"
}
Ara eliminarem tota la col·lecció amb l’ordre drop
db.dropDatabase();