input: Write a python function to simulate adding and retrieving products using Flask and PyMongo.
  assert add_product_and_get({'pid': 1, 'name': 'Laptop', 'price': 999.99}) == {'pid': 1, 'name': 'Laptop', 'price': 999.99}
  assert add_product_and_get({'pid': 2, 'name': 'Smartphone', 'price': 499.99}) == {'pid': 2, 'name': 'Smartphone', 'price': 499.99}
  assert add_product_and_get({'pid': 3, 'name': 'Headphones', 'price': 199.99}) == {'pid': 3, 'name': 'Headphones', 'price': 199.99}
output: from flask import Flask, request, jsonify
  from pymongo import MongoClient
  
  app = Flask(__name__)
  client = MongoClient('mongodb://localhost:27017/')
  db = client['productdb']
  products_collection = db['products']
  
  @app.route('/add_product', methods=['POST'])
  def add_product():
      product_data = request.json
      products_collection.insert_one(product_data)
      return jsonify(product_data), 201
  
  @app.route('/get_product/<int:pid>', methods=['GET'])
  def get_product(pid):
      product = products_collection.find_one({'pid': pid}, {'_id': 0})
      if product:
          return jsonify(product)
      return jsonify({'error': 'Product not found'}), 404
  
  def add_product_and_get(product):
      with app.test_client() as client:
          client.post('/add_product', json=product)
          response = client.get(f"/get_product/{product['pid']}")
          return response.json