 <p>I figured out that I could create a new ObjectId first then when I insert it into the mongoDb, I pass the ObjectId.str for the "_id" property, then problem resolved, both mongo db level and grails level will have String type for id field.</p> <p>Code snippet is as following for mongo javascript script:</p> <pre><code>conn = new Mongo(); db = conn.getDB("dbName"); db.user.find().forEach( function(userDoc) { // Create a new object Id objectId = new ObjectId(); db.userRole.insert({ _id: objectId.str, // Before we insert, convert it as a String role: "51437d742cd1d9e80a3f0644", user: userDoc._id }); }); </code></pre>