change document _id from object to string?

179 views Asked by At

Currently using this, but doesn't seem to be loading. Does this just take a while or am I doing something wrong? My db is on modulus which is 3.0.3 while my shell is 3.2.1

db.itemtemplates.find().snapshot().forEach(
  function (e) {
    // update document, using its own properties
    e._id = e._id.str
    db.itemtemplates.save(e);
  }
)
1

There are 1 answers

0
Alex On BEST ANSWER

The correct method to convert an ObjectId to string is toString(), see the documentation.

db.itemtemplates.find().snapshot().forEach(
  function (e) {
    // update document, using its own properties
    e._id = e._id.toString()
    db.itemtemplates.save(e);
  }
)