title: How to convert from new ObjectId() to string in Mongodb?
body: <p>Below is my code to create a review and add it to my reviews array of restaurants collections, I am also displaying this review after adding it to the collection.</p>
  <pre><code>const res = require('./restaurants');
  async create (restaurantId, title, reviewer, rating, dateOfReview, review) {
  
      
     // check(restaurantId, title, reviewer, rating, dateOfReview, review)
      restaurantId = ObjectId(restaurantId)
      const restaurantsCollection = await restaurants();
      let newReview = {
        _id: ObjectId(),
        title : title,
        reviewer : reviewer,
        rating : rating,
        dateOfReview : dateOfReview,
        review : review
      };
      
      
    
      await restaurantsCollection.updateOne({ _id : restaurantId},{ $push: {reviews: newReview} })
     
      const r = await restaurantsCollection.findOne({ _id: restaurantId });
      let len = r.reviews.length
    
      r.overallRating += rating
   
      let avg = r.overallRating/len
      
      /* await restaurantsCollection.updateOne(
        { &quot;r.overallRating&quot;: r.overallRating },
        { $set: { &quot;r.$.overallRating&quot; : avg } }
     )  */
     var query = { _id : restaurantId };
     var data = { $set : {overallRating : avg} } ;
     await restaurantsCollection.updateOne(
       query,data
     );
   
     restaurantId = restaurantId.toString().replace(/ObjectId\(&quot;(.*)&quot;\)/, &quot;$1&quot;);
      return res.get(restaurantId)
      
     
    },
  </code></pre>
  <p>restaurant.js:</p>
  <pre><code>async get(id) {
      if (!id) throw 'You must provide an id to search for';
      checkString(id);
      var checkForHexRegExp = new RegExp(&quot;^[0-9a-fA-F]{24}$&quot;);
      if(checkForHexRegExp.test(id)===false) throw 'Not a valid objectid';
      id = ObjectId(id);
      const restaurantsCollection = await restaurants();
      const res= await restaurantsCollection.findOne({ _id: id });
      if (res === null) throw 'No restaurant with that id';
      res._id = res._id.toString().replace(/ObjectId\(&quot;(.*)&quot;\)/, &quot;$1&quot;);
      return res;
    },
  </code></pre>
  <p>The output I get is:</p>
  <pre><code>{
    _id: '6174cf81053daf4b9937ef80',
    name: 'Saffron Lounge',
    location: 'SoHo, New York',
    phoneNumber: '123-456-1234',
    website: 'http://www.thesaffronlounge.com',
    priceRange: '$$$',
    cuisines: [ 'Italian' ],
    overallRating: 0.13518518518518519,
    serviceOptions: { dineIn: false, takeOut: false, delivery: true },
    reviews: [
      {
        _id: new ObjectId(&quot;6174cfb953edbe9dc5054f9a&quot;),
        title: 'bo',
        reviewer: 'dd',
        rating: 2,
        dateOfReview: '15/1/2002',
        review: ' ruh'
      },
  </code></pre>
  <p>How can I change the _id field to not have the new ObjectID and just display the string, I tried to add JSON.stringify() to the returning result but it does not return it as an object, also I tried to use:</p>
  <pre><code>toString().replace(/ObjectId\(&quot;(.*)&quot;\)/, &quot;$1&quot;);
  </code></pre>
  <p>But it does not work for the reviews as I am creating a new Object() in the create function and I don't know where to add this correctly, is there an easier way around to display:</p>
  <pre><code>_id: &quot;6174cfb953edbe9dc5054f9a&quot;
  </code></pre>