Project Setup

We’re almost ready to get started coding. In this section, we’re going to take care of some basic housekeeping and get our initial project set.

First, let’s clone saas-product into a directory.

Here are the commands I used to setup my system

mkdir hotel-booking-app
cd hotel-booking-app
git clone git@github.com:AdamMichaelArthur/saas-product.git
mv saas-product/* .
sudo rm -r saas-product
npm init
git init
git add .
git commit -m "First Commit"
npm install
cd api
npm install
cd ..
cd apiv2
npm install

You won’t be able to run the project just yet, as we’ll need to setup environment variables. We’re not going to worry about getting the project working just yet. For now, there are a few important things to understand.

There are two api directories: ‘api’ and ‘apiv2’

Our approach to API versioning is beyond the scope of this particular post. The important point is you will need to run separate node processes for both API’s for full functionality.

For now, we want to create some documentation of our Mongo Queries so we have them readily available.

At this point, I’ve got the project open in Sublime Text, my favorite IDE.

Prompt:

I am going to give you a series of mongo shell queries.  I want you to create a markdown document for documentation purposes.  I need the raw markdown so I can copy and paste it.

db.throwaway-1.listings.createIndex({ "Property.GPS": "2dsphere" });

db.listings.find({
  "Property.GPS": {
    $near: {
      $geometry: {
        type: "Point",
        coordinates: [41.025570330702735, 28.977524665462145]
      }
    }
  }
}).limit(10);

db.listings.find({
    "Property.GPS": { $near: { $geometry: { type: "Point", coordinates: [
                    41.025570330702735,
                    28.977524665462145
                ]
            }
        }
    }
},
{
    "Property.HotelName": 1,
    "Property.GPS": 1
}).limit(3);

db.listings.find({
    "Property.GPS": { $near: { $geometry: { type: "Point", coordinates: [
                        41.05314902455228,
                        29.031734625650678
                ]
            }
        }
    }
},
{
    "Property.HotelName": 1,
    "Property.GPS": 1
}).limit(3);

db.listings.aggregate([
  {
    $project: {
      amenities: {
        $objectToArray: "$Property.PropertyAmenities"
      }
    }
  },
  {
    $unwind: "$amenities"
  },
  {
    $group: {
      _id: null,
      keys: {
        $addToSet: "$amenities.k"
      }
    }
  },
  {
    $project: {
      _id: 0
    }
  }
])

db.listings.aggregate([ { $geoNear: { near: { type: "Point", coordinates: [41.025570330702735, 28.977524665462145] }, distanceField: "distance", maxDistance: 4828, /* Approx 3 miles in meters*/ spherical: true } }, { $match: { "Property.PropertyAmenities.WiFi": true, "Property.PropertyAmenities.SwimmingPool": true, "RoomType.Availability.AvailablePeriods": { $elemMatch: { StartDate: { $gte: "2023-12-01" }, EndDate: { $lte: "2023-12-15" } } } } }, { $unwind: "$RoomType" }, { $match: { "RoomType.Availability.AvailablePeriods": { $elemMatch: { StartDate: { $lte: "2023-12-01" }, EndDate: { $gte: "2023-12-15" } } } } }, { $group: { _id: "$Property.HotelName", minPrice: { $min: "$RoomType.RoomPrice" }, maxPrice: { $max: "$RoomType.RoomPrice" }, details: { $first: "$$ROOT" } } }, { $match: { minPrice: { $gte: 20 }, maxPrice: { $lte: 250 } } }] );

I do a final test to make sure that ChatGPT didn’t edit my queries and that they still work.

Next, we’re going to start planning out our API needs.

Initial API Planning

Scroll to Top