w3resource

Find listings with jumio-verified hosts and about section


Find all listings with listing_url, name, amenities, host in the listingsAndReviewscollection that have a host with a Jumio verification and a about section.

Structure of 'listingsAndReviews' collection:

 {
    _id: '10059872',
    listing_url: 'https://www.airbnb.com/rooms/10059872',
    name: 'Soho Cozy, Spacious and Convenient',
    summary: 'Clean, fully furnish, Spacious 1 bedroom flat just off the escalator in Mid Levels. 2 minutes From Soho Bar and Restaurants. Located in a quiet alley 1 minute from Sun Yat Sen',
    space: '',
    description: 'Clean, fully furnish, Spacious 1 bedroom flat just off the escalator in Mid Levels. 2 minutes From Soho Bar and Restaurants. Located in a quiet alley 1 minute from Sun Yat Sen',
    neighborhood_overview: '',
    notes: '',
    transit: '',
    access: '',
    interaction: '',
    house_rules: '',
    property_type: 'Apartment',
    room_type: 'Entire home/apt',
    bed_type: 'Real Bed',
    minimum_nights: '4',
    maximum_nights: '20',
    cancellation_policy: 'flexible',
    last_scraped: ISODate("2019-03-11T04:00:00.000Z"),
    calendar_last_scraped: ISODate("2019-03-11T04:00:00.000Z"),
    first_review: ISODate("2015-12-19T05:00:00.000Z"),
    last_review: ISODate("2018-03-27T04:00:00.000Z"),
    accommodates: 3,
    bedrooms: 1,
    beds: 2,
    number_of_reviews: 3,
    bathrooms: Decimal128("1.0"),
    amenities: [
      'Air conditioning',
      'Kitchen',
      'Smoking allowed',
      'Doorman',
      'Elevator',
      'Heating',
      'Family/kid friendly',
      'Essentials',
      '24-hour check-in',
      'translation missing: en.hosting_amenity_50'
    ],
    price: Decimal128("699.00"),
    weekly_price: Decimal128("5000.00"),
    extra_people: Decimal128("0.00"),
    guests_included: Decimal128("1"),
    images: {
      thumbnail_url: '',
      medium_url: '',
      picture_url: 'https://a0.muscache.com/im/pictures/4533a1dc-6fd8-4167-938d-391c6eebbc19.jpg?aki_policy=large',
      xl_picture_url: ''
    },
    host: {
      host_id: '51624384',
      host_url: 'https://www.airbnb.com/users/show/51624384',
      host_name: 'Giovanni',
      host_location: 'Hong Kong, Hong Kong',
      host_about: '',
      host_thumbnail_url: 'https://a0.muscache.com/im/pictures/264b82a7-756f-4da8-b607-dc9759e2a10f.jpg?aki_policy=profile_small',
      host_picture_url: 'https://a0.muscache.com/im/pictures/264b82a7-756f-4da8-b607-dc9759e2a10f.jpg?aki_policy=profile_x_medium',
      host_neighbourhood: 'Soho',
      host_is_superhost: false,
      host_has_profile_pic: true,
      host_identity_verified: false,
      host_listings_count: 1,
      host_total_listings_count: 1,
      host_verifications: [ 'email', 'phone', 'reviews', 'jumio', 'government_id' ]
    },
    address: {
      street: 'Hong Kong, Hong Kong Island, Hong Kong',
      suburb: 'Central & Western District',
      government_area: 'Central & Western',
      market: 'Hong Kong',
      country: 'Hong Kong',
      country_code: 'HK',
      location: {
        type: 'Point',
        coordinates: [ 114.15027, 22.28158 ],
        is_location_exact: true
      }
    },
    availability: {
      availability_30: 0,
      availability_60: 0,
      availability_90: 0,
      availability_365: 0
    },
    review_scores: {
      review_scores_accuracy: 10,
      review_scores_cleanliness: 10,
      review_scores_checkin: 10,
      review_scores_communication: 10,
      review_scores_location: 10,
      review_scores_value: 8,
      review_scores_rating: 100
    },
    reviews: [
      {
        _id: '56904633',
        date: ISODate("2015-12-19T05:00:00.000Z"),
        listing_id: '10059872',
        reviewer_id: '5302612',
        reviewer_name: 'Octavio',
        comments: 'The host canceled this reservation 11 days before arrival. This is an automated posting.'
      },
      {
        _id: '223175530',
        date: ISODate("2018-01-01T05:00:00.000Z"),
        listing_id: '10059872',
        reviewer_id: '48436743',
        reviewer_name: 'Ross',
        comments: 'Giovanni was very helpful and responsive to my questions. This is a great apartment that is very convenient for exploring Hong Kong.'
      },

      {
        _id: '247251577',
        date: ISODate("2018-03-27T04:00:00.000Z"),
        listing_id: '10059872',
        reviewer_id: '111288273',
        reviewer_name: 'Christian',
        comments: 'The host canceled this reservation 8 days before arrival. This is an automated posting.'
      }
    ]
  },
.......

Query:

db.listingsAndReviews.find({
  "host.host_verifications": "jumio",
  "host.host_about": { $exists: true, $ne: "" }
},
{
  "listing_url": 1,
  "name": 1,
  "amenities": 1,
  "host": 1
})

Output:

{
    _id: '1003530',
listing_url: 'https://www.airbnb.com/rooms/1003530',
name: 'New York City - Upper West Side Apt',
amenities: [
      'Internet',
      'Wifi',
      'Air conditioning',
      'Kitchen',
      'Elevator',
      'Buzzer/wireless intercom',
      'Heating',
      'Family/kid friendly',
      'Washer',
      'Dryer',
      'translation missing: en.hosting_amenity_50'
    ],
host: {
host_id: '454250',
host_url: 'https://www.airbnb.com/users/show/454250',
host_name: 'Greta',
host_location: 'New York, New York, United States',
host_about: 'By now I have lived longer in the city than the country however I feel equally at home in each. I like to keep one foot in each and help others to do the same!',
host_response_time: 'within an hour',
host_thumbnail_url: 'https://a0.muscache.com/im/pictures/f1022be4-e72a-4b35-b6d2-3d2736ddaff9.jpg?aki_policy=profile_small',
host_picture_url: 'https://a0.muscache.com/im/pictures/f1022be4-e72a-4b35-b6d2-3d2736ddaff9.jpg?aki_policy=profile_x_medium',
host_neighbourhood: '',
host_response_rate: 100,
host_is_superhost: true,
host_has_profile_pic: true,
host_identity_verified: true,
host_listings_count: 3,
host_total_listings_count: 3,
host_verifications: [
        'email',
        'phone',
        'reviews',
        'jumio',
        'offline_government_id',
        'government_id'
      ]
    }
  },
  {
    _id: '10112159',
listing_url: 'https://www.airbnb.com/rooms/10112159',
name: 'Downtown Oporto Inn (room cleaning)',
amenities: [
      'TV',
      'Cable TV',
      'Wifi',
      'Family/kid friendly',
      'Smoke detector',
      'Fire extinguisher',
      'Essentials',
      'Shampoo',
      'Lock on bedroom door',
      'Hangers',
      'Hair dryer',
      'Hot water',
      'Long term stays allowed',
      'Other'
    ],
host: {
host_id: '2649859',
host_url: 'https://www.airbnb.com/users/show/2649859',
host_name: 'Elisabete',
host_location: 'Porto, Porto, Portugal',
host_about: "Souactiva, responsável, interessadaporleitura, por cinema e porpasseio. Sobretudo, souescritora. Adoroescrever! Escrevosobre o Porto e sobre as pessoas, poissão o que de maisimportantetemos! Venhaconhecer o nossoespaço, queinspirou o nascimento de doislivros, jáeditados, além de outros dois, aindanaforja... | I'm an active, responsible person, who loves reading, movies and walking through our beautiful country. Mainly, I'm a writer. I love to write! I write about Oporto and about people, cause they are the most important thing we have. Come and know our space, where two books were already born, and two others are on their way out..",
host_thumbnail_url: 'https://a0.muscache.com/im/pictures/3e7725d5-79ea-4290-a99c-5bd5e0691f02.jpg?aki_policy=profile_small',
host_picture_url: 'https://a0.muscache.com/im/pictures/3e7725d5-79ea-4290-a99c-5bd5e0691f02.jpg?aki_policy=profile_x_medium',
host_neighbourhood: '',
host_is_superhost: false,
host_has_profile_pic: true,
host_identity_verified: true,
host_listings_count: 2,
host_total_listings_count: 2,
host_verifications: [ 'email', 'phone', 'reviews', 'jumio', 'government_id' ]
    }
  },
.....

Explanation:

The said query in MongoDB that retrieves documents with listing_url, name, amenities, and host fields from the listingsAndReviews collection that have both "TV" and "Wifi" listed in their amenities array.

In the find{} method the first parameter filters the documents in the listingsAndReviews collection where the host has a Jumio verification.

The $exists and $ne operator checks whether the host field has a non-empty host_about field. This ensures that the host has an about section.

The projection part of the query includes the listing_url, name, amenities, and host fields in the result set.

Improve this sample solution and post your code through Disqus.

Previous: Retrieve documents with listing details and amenities in MongoDB.
Next: Retrieve listings with multiple listings by hosts.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.