MongoDB WriteError "code" : 9

4.1k views Asked by At

I am trying to delete some records from MongoDB that have dirty values, but whenever I try to delete it, I am getting the writeError with code 9.

A sample of the dirty document is as follows:

{
    "_id" : "some_unique_id_abcd",
    "tmp" : "1415772407377",
    "hiv" : "0.0",
    "liv" : "0.0",
    "oindx" : "0.0"
}

The remove command executed is as follows:

db.myCollection.remove({"_id" : "some_unique_id_abcd"});

The following error is thrown

WriteResult({
    "writeError" : {
        "code" : 9,
        "errmsg" : "wrong type for 'delete' field, expected string, 
                    found delete: 0.0"
    }
})

Any idea what exactly this error is about or how to get around it?

2

There are 2 answers

1
anhlc On BEST ANSWER

This is what the error code means:

error_code("FailedToParse", 9)
3
wdberkeley On

From the capped collection docs that BatScream linked:

You cannot delete documents from a capped collection. To remove all records from a capped collection, use the ‘emptycapped’ command. To remove the collection entirely, use the drop() method.

Documents expire from the capped collection as new documents are inserted. You cannot manually delete documents. See the docs for more info and warnings about capped collections.