Created
August 14, 2021 13:08
-
-
Save FaizUlHassan123/80c5420150681c4a28db4af3abdec212 to your computer and use it in GitHub Desktop.
mongodb - google cloud functions write example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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