Edijae Crusar
Edijae Crusar

Reputation: 3541

how to clear _SCHEMA collection in mongodb

I have a collection in my mongo database. in this collection, i store documents where each document has a field called owner. This field was of type ParseUser but I changed the field type to stringso every document that is been uploaded to the collection has a string value and not a ParseUser value. I even went ahead and cleared the collection using the following command

db.MyCollection.remove({})

The problem is all my uploads to the collection fails with the error

schema mismatch for MyCollection.owner; expected Pointer<_User> but got String

I've tried

db._SCHEMA.remove({})

which fails with error

[js] TypeError: db._SCHEMA is undefined : @(shell):1:1

I've also tried the command below

db.runCommand({collMod: "MyCollection",validator:{$jsonSchema:{properties:{owner:{bsonType: "string"}}}}})

which returns

{ "ok" : 1 }

But uploads still fails with the same message.How can i clear MyCollection schema from _SCHEMA collection?

Upvotes: 1

Views: 740

Answers (1)

Edijae Crusar
Edijae Crusar

Reputation: 3541

I managed to access the _SCHEMA collection, using the command below

db.getCollection("_SCHEMA")

and everything else like deleting all rows/documents in the collection was easy

db.getCollection("_SCHEMA").remove({})

Upvotes: 1

Related Questions