INNER CODE UNIT · JavaScript
createListing
mongodb-developer/nodejs-quickstart · changeStreamsTestData.js:103
async function createListing(client, newListing) {
// See http://bit.ly/Node_InsertOne for the insertOne() docs
const result = await client.db("sample_airbnb").collection("listingsAndReviews").insertOne(newListing);
console.log(`New listing created with the following id: ${result.insertedId}`);
return result.insertedId;
}
/**
* Update 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 update
* @param {object} updatedListing An object containing all of the properties to be updated for the given listing
*/
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.`);