Over a million developers have joined DZone.

Please, Stop Using MongoDB as a SQL Database

DZone's Guide to

Please, Stop Using MongoDB as a SQL Database

· Database Zone
Free Resource

Whether you work in SQL Server Management Studio or Visual Studio, Redgate tools integrate with your existing infrastructure, enabling you to align DevOps for your applications with DevOps for your SQL Server databases. Discover true Database DevOps, brought to you in partnership with Redgate.

I’ve read in numerous sites and blog posts some kind of tips or tutorials about MongoDB that includes the most SQL-ish structure that you wouldn’t do in MongoDB (of course not all situations fit this, but it’s a good approach in some cases)

I’m talking about embedded objects collections. In an usual SQL database you would do a JOIN to find all the objects that are connected to a simple row. We all have done that, but… In MongoDB, if it doesn’t mean content replication, this should be achieved throught embedded collections.

Take this example with mongoose and node.js:

var NotificationSchema = new Schema({
type: String,
message: String,
createdAt: {type:Date, default: Date.now},
read: {type: Boolean, default: false}
var UserSchema = new Schema({
username: String,
notifications: [NotificationSchema]

This is a real example that’s been used on production (obviously whithout some fields).

With this simple declaration, everytime you access User model you will retrieve notifications too. Of course if you want to send users over the net and don’t want to pass all of this you could use underscore’s pick to choose what to send or not (that was just a little tip for express users :) )

It’s easier than you think to extend DevOps practices to SQL Server with Redgate tools. Discover how to introduce true Database DevOps, brought to you in partnership with Redgate


Published at DZone with permission of Javier Manzano, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}