Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Developing Your Applications More Efficiently with MongoDB Atlas Serverless Instances

If you’re a developer, worrying about your database is not necessarily something you want to do. You likely don’t want to spend your time provisioning or sizing clusters as the demand of your application changes. You probably also don’t want to worry about breaking the bank if you’ve scaled something incorrectly.

With MongoDB Atlas, you have a few deployment options to choose from when it comes to your database. While you could choose a pre-provisioned shared or dedicated cluster, you’re still stuck having to size and estimate the database resources you will need and subsequently managing your cluster capacity to best fit demand. While a pre-provisioned cluster isn’t necessarily a bad thing, it might not make sense if your development becomes idle or you’re expecting frequent periods of growth or decline. Instead, you can opt for a serverless instance to help remove the capacity management burden and free up time to dedicate to writing code. Serverless instances provide an on-demand database endpoint for your application that will automatically scale up and down to zero with application demand and only charge you based on your usage.

In this short and sweet tutorial, we’ll see how easy it is to get started with a MongoDB Atlas serverless instance and how to begin to develop an application against it.

Read More

Randomizing MongoDB Document Fields on a Repeating Timer with Node.js

About a year ago I created a game with MongoDB and Unity and wrote about it in a previous tutorial. The idea was to demonstrate how features within the game could be synchronized to each player in near real-time. At the time, synchronization happened through a web dashboard where the player could select features to sync and they would then sync to the game client, wherever in the world it might be.

Recently, the game was adopted to be a demo at several conferences. The problem was that switching between the game and the web dashboard to demonstrate features being synchronized was a hassle. As a result, I decided to write a script that did this automatically on a timer.

In this quick tutorial, we’re going to see how to update documents within MongoDB on a timer, something that might be useful to you for demos and other potential use-cases.

Read More

Developing a Web Application with Netlify Serverless Functions and MongoDB

As I mentioned in a previous tutorial, I’m a big fan of Netlify and the services they offer developers—my favorite of their services being their static website hosting and serverless functions. When combining the two, you can deploy a complex website or web application with a back end, without ever worrying about infrastructure or potentially complex API design.

So how does that work with a database like MongoDB?

If you’ve ever dabbled with serverless functions before, you might be aware that they are not always available for consumption. Many serverless functions exist for a defined amount of time and then are shut down until they are executed again. With this in mind, the connection to a database might not always be available like it would be in an application built with Express Framework, for example. You could establish a connection every time a function is called, but then you risk too many connections, which might overload your database.

So what do you do?

In this tutorial, we’re going to see how to build and deploy a simple web application using Netlify Functions and MongoDB Atlas. For this particular tutorial, we’ll be using the Node.js driver for MongoDB, but both Netlify and MongoDB support the use of other languages and drivers as well.

Read More

Using LINQ to Query MongoDB in a .NET Core Application

If you’ve been keeping up with my series of tutorials around .NET Core and MongoDB, you’ll likely remember that we explored using the Find operator to query for documents as well as an aggregation pipeline. Neither of these previously explored subjects are too difficult, but depending on what you’re trying to accomplish, they could be a little messy. Not to mention, they aren’t necessarily “the .NET way” of doing business.

This is where LINQ comes into the mix of things!

With Language Integrated Queries (LINQ), we can use an established and well known C# syntax to work with our MongoDB documents and data.

In this tutorial, we’re going to look at a few LINQ queries, some as a replacement to simple queries using the MongoDB Query API and others as a replacement to more complicated aggregation pipelines.

Read More

Add a Comments Section to an Eleventy Website with MongoDB and Netlify

I’m a huge fan of static generated websites! From a personal level, I have The Polyglot Developer, Poké Trainer Nic, and The Tracy Developer Meetup, all three of which are static generated websites built with either Hugo or Eleventy. In addition to being static generated, all three are hosted on Netlify.

I didn’t start with a static generator though. I started on WordPress, so when I made the switch to static HTML, I got a lot of benefits, but I ended up with one big loss. The comments of my site, which were once stored in a database and loaded on-demand, didn’t have a home.

Fast forward to now, we have options!

In this tutorial, we’re going to look at maintaining a static generated website on Netlify with Eleventy, but the big thing here is that we’re going to see how to have comments for each of our blog pages.

Read More

Joining Collections in MongoDB with .NET Core and an Aggregation Pipeline

If you’ve been keeping up with my .NET Core series on MongoDB, you’ll remember that we explored creating a simple console application as well as building a RESTful API with basic CRUD support. In both examples, we used basic filters when interacting with MongoDB from our applications.

But what if we need to do something a bit more complex, like join data from two different MongoDB collections?

In this tutorial, we’re going to take a look at aggregation pipelines and some of the ways that you can work with them in a .NET Core application.

Read More

Create a RESTful API with .NET Core and MongoDB

If you’ve been keeping up with my development content, you’ll remember that I recently wrote Build Your First .NET Core Application with MongoDB Atlas, which focused on building a console application that integrated with MongoDB. While there is a fit for MongoDB in console applications, many developers are going to find it more valuable in web applications.

In this tutorial, we’re going to expand upon the previous and create a RESTful API with endpoints that perform basic create, read, update, and delete (CRUD) operations against MongoDB Atlas.

Read More