Mongodb. Convert field to bool

Posted on

Question :

I’m trying to change field type to bool among all documents in collection. Here is the code

db.product.find().forEach(function(doc) {
if (doc.checked === "Y") {
doc.checked = true;
} else if (doc.checked === "N") {
doc.checked = false;

Mongodb returns no error but doesn’t convert fields.

Answer :

I solved problem using ‘db.product.update’ instead of ‘’

Leave a Reply

Your email address will not be published. Required fields are marked *