-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.jsonl
12 lines (12 loc) · 23 KB
/
javascript.jsonl
1
2
3
4
5
6
7
8
9
10
11
12
{"prompt": "// create a global mongodb client using the mongodb driver", "ground_truth": "const MongoClient = require(\"mongodb\").MongoClient;"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id", "ground_truth": "const ObjectId = require(\"mongodb\").ObjectId;"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database", "ground_truth": "let _db;"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable", "ground_truth": "const connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable\nconst connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};\n\n// connect to the database", "ground_truth": "connectToDatabase(\n \"mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority\"\n);"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable\nconst connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};\n\n// connect to the database\nconnectToDatabase(\n \"mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority\"\n);\n\n// create a function to add a new customer to the database in the customers collection using the _db connection. Return the inserted document _id", "ground_truth": "const addCustomer = (customer) => {\n return _db\n .collection(\"customers\")\n .insertOne(customer)\n .then((result) => {\n return result.insertedId;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable\nconst connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};\n\n// connect to the database\nconnectToDatabase(\n \"mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority\"\n);\n\n// create a function to add a new customer to the database in the customers collection using the _db connection. Return the inserted document _id\nconst addCustomer = (customer) => {\n return _db\n .collection(\"customers\")\n .insertOne(customer)\n .then((result) => {\n return result.insertedId;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create an update function to set the customers discount level based on the customers _id", "ground_truth": "const setDiscountLevel = (customerId, discountLevel) => {\n return _db\n .collection(\"customers\")\n .updateOne(\n // convert the customerId from a string to a mongodb object id\n { _id: new ObjectId(customerId) },\n { $set: { discountlevel: discountLevel } }\n )\n .then((result) => {\n return result.modifiedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable\nconst connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};\n\n// connect to the database\nconnectToDatabase(\n \"mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority\"\n);\n\n// create a function to add a new customer to the database in the customers collection using the _db connection. Return the inserted document _id\nconst addCustomer = (customer) => {\n return _db\n .collection(\"customers\")\n .insertOne(customer)\n .then((result) => {\n return result.insertedId;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create an update function to set the customers discount level based on the customers _id\nconst setDiscountLevel = (customerId, discountLevel) => {\n return _db\n .collection(\"customers\")\n .updateOne(\n // convert the customerId from a string to a mongodb object id\n { _id: new ObjectId(customerId) },\n { $set: { discountlevel: discountLevel } }\n )\n .then((result) => {\n return result.modifiedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find a customer based on their _id", "ground_truth": "const findCustomerById = (customerId) => {\n return _db\n .collection(\"customers\")\n .findOne({ _id: new ObjectId(customerId) })\n .then((customer) => {\n return customer;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable\nconst connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};\n\n// connect to the database\nconnectToDatabase(\n \"mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority\"\n);\n\n// create a function to add a new customer to the database in the customers collection using the _db connection. Return the inserted document _id\nconst addCustomer = (customer) => {\n return _db\n .collection(\"customers\")\n .insertOne(customer)\n .then((result) => {\n return result.insertedId;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create an update function to set the customers discount level based on the customers _id\nconst setDiscountLevel = (customerId, discountLevel) => {\n return _db\n .collection(\"customers\")\n .updateOne(\n // convert the customerId from a string to a mongodb object id\n { _id: new ObjectId(customerId) },\n { $set: { discountlevel: discountLevel } }\n )\n .then((result) => {\n return result.modifiedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find a customer based on their _id\nconst findCustomerById = (customerId) => {\n return _db\n .collection(\"customers\")\n .findOne({ _id: new ObjectId(customerId) })\n .then((customer) => {\n return customer;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find all customers with a discount level greater than the specified discount level", "ground_truth": "const findCustomersByDiscountLevel = (discountLevel) => {\n return _db\n .collection(\"customers\")\n .find({ discountlevel: { $gt: discountLevel } })\n .toArray()\n .then((customers) => {\n return customers;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable\nconst connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};\n\n// connect to the database\nconnectToDatabase(\n \"mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority\"\n);\n\n// create a function to add a new customer to the database in the customers collection using the _db connection. Return the inserted document _id\nconst addCustomer = (customer) => {\n return _db\n .collection(\"customers\")\n .insertOne(customer)\n .then((result) => {\n return result.insertedId;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create an update function to set the customers discount level based on the customers _id\nconst setDiscountLevel = (customerId, discountLevel) => {\n return _db\n .collection(\"customers\")\n .updateOne(\n // convert the customerId from a string to a mongodb object id\n { _id: new ObjectId(customerId) },\n { $set: { discountlevel: discountLevel } }\n )\n .then((result) => {\n return result.modifiedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find a customer based on their _id\nconst findCustomerById = (customerId) => {\n return _db\n .collection(\"customers\")\n .findOne({ _id: new ObjectId(customerId) })\n .then((customer) => {\n return customer;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find all customers with a discount level greater than the specified discount level\nconst findCustomersByDiscountLevel = (discountLevel) => {\n return _db\n .collection(\"customers\")\n .find({ discountlevel: { $gt: discountLevel } })\n .toArray()\n .then((customers) => {\n return customers;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function that deletes a customer based on their _id", "ground_truth": "const deleteCustomer = (customerId) => {\n return _db\n .collection(\"customers\")\n .deleteOne({ _id: new ObjectId(customerId) })\n .then((result) => {\n return result.deletedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable\nconst connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};\n\n// connect to the database\nconnectToDatabase(\n \"mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority\"\n);\n\n// create a function to add a new customer to the database in the customers collection using the _db connection. Return the inserted document _id\nconst addCustomer = (customer) => {\n return _db\n .collection(\"customers\")\n .insertOne(customer)\n .then((result) => {\n return result.insertedId;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create an update function to set the customers discount level based on the customers _id\nconst setDiscountLevel = (customerId, discountLevel) => {\n return _db\n .collection(\"customers\")\n .updateOne(\n // convert the customerId from a string to a mongodb object id\n { _id: new ObjectId(customerId) },\n { $set: { discountlevel: discountLevel } }\n )\n .then((result) => {\n return result.modifiedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find a customer based on their _id\nconst findCustomerById = (customerId) => {\n return _db\n .collection(\"customers\")\n .findOne({ _id: new ObjectId(customerId) })\n .then((customer) => {\n return customer;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find all customers with a discount level greater than the specified discount level\nconst findCustomersByDiscountLevel = (discountLevel) => {\n return _db\n .collection(\"customers\")\n .find({ discountlevel: { $gt: discountLevel } })\n .toArray()\n .then((customers) => {\n return customers;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function that deletes a customer based on their _id\nconst deleteCustomer = (customerId) => {\n return _db\n .collection(\"customers\")\n .deleteOne({ _id: new ObjectId(customerId) })\n .then((result) => {\n return result.deletedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function that pushes a new purchase to the customers purchases array", "ground_truth": "const addPurchase = (customerId, purchase) => {\n return _db\n .collection(\"customers\")\n .updateOne(\n { _id: new ObjectId(customerId) },\n { $push: { purchases: purchase } }\n )\n .then((result) => {\n return result.modifiedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};"}
{"prompt": "// create a global mongodb client using the mongodb driver\nconst MongoClient = require(\"mongodb\").MongoClient;\n// require ObjectId from the mongodb driver to convert a string to a mongodb object id\nconst ObjectId = require(\"mongodb\").ObjectId;\n\n// create a global variable to hold the database\nlet _db;\n\n// create a function to connect to the database using a URI and ping the database using the admin command to check if the connection is successful. Store the connection in the _db variable\nconst connectToDatabase = (uri) => {\n return (\n MongoClient.connect(uri, { useNewUrlParser: true })\n .then((client) => {\n _db = client.db(\"myFirstDatabase\");\n return _db.admin().ping();\n })\n .then((pingResult) => {\n if (pingResult.ok) {\n console.log(\"Connection to MongoDB successful\");\n } else {\n throw new Error(\"Connection to MongoDB failed\");\n }\n })\n .catch((err) => {\n console.log(err);\n throw err;\n })\n );\n};\n\n// connect to the database\nconnectToDatabase(\n \"mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority\"\n);\n\n// create a function to add a new customer to the database in the customers collection using the _db connection. Return the inserted document _id\nconst addCustomer = (customer) => {\n return _db\n .collection(\"customers\")\n .insertOne(customer)\n .then((result) => {\n return result.insertedId;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create an update function to set the customers discount level based on the customers _id\nconst setDiscountLevel = (customerId, discountLevel) => {\n return _db\n .collection(\"customers\")\n .updateOne(\n // convert the customerId from a string to a mongodb object id\n { _id: new ObjectId(customerId) },\n { $set: { discountlevel: discountLevel } }\n )\n .then((result) => {\n return result.modifiedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find a customer based on their _id\nconst findCustomerById = (customerId) => {\n return _db\n .collection(\"customers\")\n .findOne({ _id: new ObjectId(customerId) })\n .then((customer) => {\n return customer;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function to find all customers with a discount level greater than the specified discount level\nconst findCustomersByDiscountLevel = (discountLevel) => {\n return _db\n .collection(\"customers\")\n .find({ discountlevel: { $gt: discountLevel } })\n .toArray()\n .then((customers) => {\n return customers;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function that deletes a customer based on their _id\nconst deleteCustomer = (customerId) => {\n return _db\n .collection(\"customers\")\n .deleteOne({ _id: new ObjectId(customerId) })\n .then((result) => {\n return result.deletedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// create a function that pushes a new purchase to the customers purchases array\nconst addPurchase = (customerId, purchase) => {\n return _db\n .collection(\"customers\")\n .updateOne(\n { _id: new ObjectId(customerId) },\n { $push: { purchases: purchase } }\n )\n .then((result) => {\n return result.modifiedCount;\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};\n\n// Calculate the total purchases for each customer using $sum, and return a JSON string.", "ground_truth": "const calculateTotalPurchases = () => {\n return _db\n .collection(\"customers\")\n .aggregate([\n {\n $project: {\n _id: 1,\n name: 1,\n totalPurchases: { $sum: \"$purchases.price\" },\n },\n },\n ])\n .toArray()\n .then((result) => {\n return JSON.stringify(result);\n })\n .catch((err) => {\n console.log(err);\n throw err;\n });\n};"}