Skip to content

Instantly share code, notes, and snippets.

@FaizUlHassan123
Created August 14, 2021 13:08
Show Gist options
  • Save FaizUlHassan123/80c5420150681c4a28db4af3abdec212 to your computer and use it in GitHub Desktop.
Save FaizUlHassan123/80c5420150681c4a28db4af3abdec212 to your computer and use it in GitHub Desktop.
mongodb - google cloud functions write example
const { MongoClient } = require("mongodb");
// // Replace the uri string with your MongoDB deployment's connection string.
const url = "monGoDb uri";
// //get all rows from collections
exports.helloWorld = (req, res) => {
MongoClient.connect(url, function(err, db) {
if (err) throw res.status(200).send(err);
console.log("Connected successfully to server");
var dbo = db.db("DataBaseName");
dbo.collection("Collectio_name").find({}).toArray(function(err, result) {
if (err) throw err;
// console.log(result);
res.status(200).send(result);
db.close();
});
});
};
{
"name": "sample-http",
"version": "0.0.1",
"dependencies": {
"babel-runtime": "^6.23.0",
"node": "^16.6.1",
"mongodb": "^4.1.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment