{"componentChunkName":"component---src-templates-single-blogpost-js","path":"/blog/mern-stack-part-1-create-a-mongodb-database","result":{"data":{"contentfulBlogPost":{"title":"MERN stack - Part 1: create a MongoDB database","slug":"mern-stack-part-1-create-a-mongodb-database","id":"c47531b4-c920-5c3e-be7c-4a197a6e382f","createdAt":"24. März 2020","category":[{"title":"Node.js","slug":"node-js","id":"0c5ec24f-7db8-5e3c-bf01-d8dc8b8c4273","blog_post":[{"title":"Express","slug":"express","image":{"fluid":{"src":"//images.ctfassets.net/843vngvcufpj/4Joi19CFYut4ELjuW2IWWh/15747b57ff62334f588f562983070117/gray-laptop-computer-showing-html-codes-in-shallow-focus-160107.jpg?w=800&q=50"}},"id":"69b82f2b-2668-5e1b-be2d-02a4b145c9c6","createdAt":"13. April 2020","childContentfulBlogPostContentTextNode":{"childMarkdownRemark":{"excerpt":"mandatory - Node.js needs to be installed  npm i express Middleware Functions have access to the…"}}},{"title":"Node.js with Express Framework","slug":"node-js-with-express-framework","image":{"fluid":{"src":"//images.ctfassets.net/843vngvcufpj/3aWpunSqJ3zvCKn5Jw74bX/f9798361bc96ba1011ba2473b6520ca1/working-macbook-computer-keyboard-34577.jpg?w=800&q=50"}},"id":"d13b4dd7-05e9-547c-bd10-76cec963ab59","createdAt":"04. April 2020","childContentfulBlogPostContentTextNode":{"childMarkdownRemark":{"excerpt":""}}},{"title":"MERN stack - Part 1: create a MongoDB database","slug":"mern-stack-part-1-create-a-mongodb-database","image":{"fluid":{"src":"//images.ctfassets.net/843vngvcufpj/5qYVUINZNZkZwB9wK86kOT/810ce3134de1ce5846f9235c233bc510/og-meta-image-01-vz0dwahmtr.png?w=800&q=50"}},"id":"c47531b4-c920-5c3e-be7c-4a197a6e382f","createdAt":"24. März 2020","childContentfulBlogPostContentTextNode":{"childMarkdownRemark":{"excerpt":"Install dependencies"}}}]}],"content":{"childMarkdownRemark":{"html":"<p>Install dependencies</p>\n<pre><code>npm i mongodb\n</code></pre>\n<pre><code>const { MongoClient } = require('mongodb');\n\nasync function main() {\n    /**\n     * Connection URI. Update &#x3C;username>, &#x3C;password>, and &#x3C;your-cluster-url> to reflect your cluster.\n     * See https://docs.mongodb.com/ecosystem/drivers/node/ for more details\n     */\n    const uri = \"mongodb+srv://username:password@cluster0-n3aik.mongodb.net/test?retryWrites=true&#x26;w=majority\";\n\n    /**\n     * The Mongo Client you will use to interact with your database\n     * See https://mongodb.github.io/node-mongodb-native/3.3/api/MongoClient.html for more details\n     */\n    const client = new MongoClient(uri);\n\n    try {\n        // Connect to the MongoDB cluster\n        await client.connect();\n\n        // Make the appropriate DB calls\n        await listDatabases(client);\n\n    } catch (e) {\n        console.error(e);\n    } finally {\n        // Close the connection to the MongoDB cluster\n        await client.close();\n    }\n}\n\nmain().catch(console.error);\n\n/**\n * Print the names of all available databases\n * @param {MongoClient} client A MongoClient that is connected to a cluster\n */\nasync function listDatabases(client) {\n    databasesList = await client.db().admin().listDatabases();\n\n    console.log(\"Databases:\");\n    databasesList.databases.forEach(db => console.log(` - ${db.name}`));\n};\n</code></pre>","timeToRead":1}}},"allContentfulCategory":{"nodes":[{"title":"Google Tag Manager","slug":"google-tag-manager","id":"d0a285b4-b818-5612-8fdc-5f325aa48eb4"},{"title":"Axios","slug":"axios","id":"36071d22-d950-5e0e-8832-52a4f31016bf"},{"title":"Redux","slug":"redux","id":"89dcb61e-1b22-5795-9618-daa15e889512"},{"title":"Express","slug":"express","id":"eff898c7-be39-553c-a199-a8b67af03038"},{"title":"Node.js","slug":"node-js","id":"0c5ec24f-7db8-5e3c-bf01-d8dc8b8c4273"},{"title":"Git","slug":"git","id":"995d33c2-1a26-52b1-81b1-a7c5dfefbb4c"},{"title":"HTML","slug":"html","id":"368ff1b9-f81e-5748-8ea5-5c257ed913f9"},{"title":"GraphQL","slug":"graphql","id":"8101a2c8-2d15-5297-bfd1-d213d77b9ce8"},{"title":"Javascript","slug":"javascript","id":"c5c3bf5b-ef37-5b26-af84-dfb083fecabf"},{"title":"styled-components","slug":"styled-components","id":"f8aeb8c8-4780-5b97-a787-f278af851268"},{"title":"Material UI","slug":"material-ui","id":"9002ca9c-ae85-58b1-abd4-d467f490bec8"},{"title":"CSS","slug":"css","id":"334376eb-4c45-5412-8b19-80f1a16d19e5"},{"title":"Gatsby","slug":"gatsby","id":"8d653418-2491-59d6-a2ef-367d1a6d0a28"},{"title":"React","slug":"react","id":"0bdfb3a0-b67b-5b9a-802a-7182aa70702b"}]}},"pageContext":{"slug":"mern-stack-part-1-create-a-mongodb-database","title":"MERN stack - Part 1: create a MongoDB database"}}}