INNER CODE UNIT · JavaScript
createListing
mongodb-developer/nodejs-quickstart · create.js:73
async function createListing(client, newListing){
// See https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#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}`);
}
/**
* Create multiple Airbnb listings
* @param {MongoClient} client A MongoClient that is connected to a cluster with the sample_airbnb database
* @param {Object[]} newListings The new listings to be added
*/
async function createMultipleListings(client, newListings){
// See https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#insertMany for the insertMany() docs
const result = await client.db("sample_airbnb").collection("listingsAndReviews").insertMany(newListings);
console.log(`${result.insertedCount} new listing(s) created with the following id(s):`);
console.log(result.insertedIds);
}