INNER CODE UNIT · JavaScript

updateListing

mongodb-developer/nodejs-quickstart · changeStreamsTestData.js:116

async function updateListing(client, listingId, updatedListing) {
    // See http://bit.ly/Node_updateOne for the updateOne() docs
    const result = await client.db("sample_airbnb").collection("listingsAndReviews").updateOne({ _id: listingId }, { $set: updatedListing });

    console.log(`${result.matchedCount} document(s) matched the query criteria.`);
    console.log(`${result.modifiedCount} document(s) was/were updated.`);
}

/**
 * Delete an Airbnb listing
 * @param {MongoClient} client A MongoClient that is connected to a cluster with the sample_airbnb database
 * @param {String} listingId The id of the listing you want to delete
 */
async function deleteListing(client, listingId) {
    // See http://bit.ly/Node_deleteOne for the deleteOne() docs
    const result = await client.db("sample_airbnb").collection("listingsAndReviews").deleteOne({ _id: listingId });

    console.log(`${result.deletedCount} document(s) was/were deleted.`);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…