180

MongoDB vs Firebase

What are some quantitative advantages of using Firebase over MongoDB? (not opinions)

I know that Firebase is a cloud-based service with its own API, but I feel like Mongo may give me greater control in the long run.

itsclarke
  • 8,622
  • 6
  • 33
  • 50
  • 70
    @David It is not opinion based. The OP is *not* asking which is better (which would be opinion based) but is asking of benefits (if any) of FB over MongoDb. To have opinion we need to pull here benefits of both and drawbacks of both and judge which tech might be preferred – Kirill Slatin Mar 25 '15 at 00:21
  • 1
    I would recommend @itsclarke to read this up: https://crisp.chat/blog/why-you-should-never-use-firebase-realtime-database/ – Junior Mayhé Jul 22 '17 at 19:26
  • 5
    @KirillSlatin This question has now been closed. You can read why questions like this are not appreciated in the [Gorilla vs Shark blog post](https://stackoverflow.blog/2011/08/16/gorilla-vs-shark/). While the _not constructive_ reason referred to in this blog is no longer available, it's still very broad (enumerating all the differences in an answer is tedious), very time-based (features might be added that change this), and generally not a good fit for this site. – Erik A Aug 07 '18 at 09:14
  • 2
    why on earth would this question, that is highly useful information, be closed? This is one of the many serious problems with SO. Its discourages others from asking actually useful questions that others can greatly benefit from. – Uriel Jun 09 '21 at 16:43
  • 3
    @Uriel The question was closed because it's asking for 'advantages' of one database over the other - and that's tough; an 'advantage' to you may not be an 'advantage' to me (so it becomes more use case dependent) Most importantly though, both MongoDB and Firebase are suites of services so it's not asking about a specific product. They also serve different purposes if we include MongoDB Realm in the mix, which is an offline first database whereas Firebase is online first with offline persistence. It's also a 6 year old question and some things have changed for both platforms. – Jay Jun 11 '21 at 17:57

8 Answers8

142
  • Firebase is a real-time engine with backward connectivity. I.e. you might build a cross-platform app where clients subscribe to events on specific data and server actively informs clients about changes
  • The data layer is hosted for you. Mind that it is highly scalable. It's a nice kickstarter solution. Including auth management
  • Geo-Fire. Real-time geo coordinates solution.
  • Evident drawbacks of Firebase are:
    • You have to pay for it as soon as you start growing
    • You can't host datalayer (if owning data is critical or you develop an app for some separated subnet)

EDIT: here is a nice article how to replace Firebase in your app with Node.js+MongoDb. It shows how much work you would have to do on your own, and explains, IMHO, why a startup (small app) should begin with Firebase (if real-time updates to clients are required) and proceed with MongoDb (in any case self-written solution) if the project keeps evolving

EDIT 2: after being acquired by Google Firebase now offers various perks on top of its basic features which you would struggle to build on your own:

  • For development

    • Cloud Messaging: Deliver and receive messages across platforms reliably
    • File Storage: Easy file storage (including iOS)
    • Hosting: deliver static files from Firebase's servers (Included in Free plan)
    • Crash Reporting: Not a full logging service, but crucial help
  • For growth

Todd
  • 652
  • 2
  • 19
  • 37
Kirill Slatin
  • 6,085
  • 3
  • 18
  • 38
44

Apples and oranges. Firebase is a Backend-as-a-Service containing identity management, realtime data views and a document database. It runs in the cloud.

MongoDB on the other hand is a full fledged database with a rich query language. In principle it runs on your own machine, but there are cloud providers.

If you are looking for the database component only MongoDB is much more mature and feature-rich.

Kees de Kooter
  • 7,078
  • 5
  • 38
  • 45
36

Firebase is designed for real-time updates. It easily integrates with angular. Both are NoSQL databases. MongoDB can also do this with Angular through Socket.io integration. Meteor.js also makes use of MongoDB with an open socket connection for real-time updates.

MongoDB can be run locally, or hosted on many different cloud based providers. Firebase, in my opinion is great for smaller apps, very quick to get up and running. MongoDB is ideal for more robust larger apps, real-time integration is possible but it takes a bit more work.

byrdr
  • 5,197
  • 12
  • 48
  • 78
31

After using Firebase a considerable amount I've come to find something.

If you intend to use it for large, real time apps, it isn't the best choice. It has its own wide array of problems including a bad error handling system and limitations. You will spend significant time trying to understand Firebase and it's kinks. It's also quite easy for a project to become a monolithic thing that goes out of control. MongoDB is a much better choice as far as a backend for a large app goes.

However, if you need to make a small app or quickly prototype something, Firebase is a great choice. It'll be incredibly easy way to hit the ground running.

Ramzi C.
  • 1,691
  • 1
  • 14
  • 27
26

I will answer this question in terms of AngularFire, Firebase's library for Angular.

  1. Tl;dr: superpowers. :-)

  2. AngularFire's three-way data binding. Angular binds the view and the $scope, i.e., what your users do in the view automagically updates in the local variables, and when your JavaScript updates a local variable the view automagically updates. With Firebase the cloud database also updates automagically. You don't need to write $http.get or $http.put requests, the data just updates.

  3. Five-way data binding, and seven-way, nine-way, etc. I made a tic-tac-toe game using AngularFire. Two players can play together, with the two views updating the two $scopes and the cloud database. You could make a game with three or more players, all sharing one Firebase database.

  4. AngularFire's OAuth2 library makes authorization easy with Facebook, GitHub, Google, Twitter, tokens, and passwords.

  5. Double security. You can set up your Angular routes to require authorization, and set up rules in Firebase about who can read and write data.

  6. There's no back end. You don't need to make a server with Node and Express. Running your own server can be a lot of work, require knowing about security, require that someone do something if the server goes down, etc.

  7. Fast. If your server is in San Francisco and the client is in San Jose, fine. But for a client in Bangalore connecting to your server will be slower. Firebase is deployed around the world for fast connections everywhere.

Thomas David Kehoe
  • 10,040
  • 14
  • 61
  • 100
  • what is Fireloop?,is this is a way of writing a rest api with the firebase ? – ashishSober Jan 02 '17 at 13:41
  • actually i think angularfire is amazing, is there any way u can take it and pass it over to use with your own database system?, in this case with Mongo, so it would be amazing u can make use of three data-way binding and also to be able to instantaneously update your values – Kross Jul 24 '17 at 08:50
  • I like your last part of comment: "Firebase is deployed around the world for fast connections everywhere." – Lester Mar 12 '18 at 19:57
18

Firebase is a suite of features .

  • Realtime Database
  • Hosting
  • Authentication
  • Storage
  • Cloud Messaging
  • Remote Config
  • Test Lab
  • Crash Reporting
  • Notifications
  • App Indexing
  • Dynamic Links
  • Invites
  • AdWords
  • AdMob

I believe you are trying to compare Firebase Realtime Database with Mongo DB . Firebase Realtime Database stores data as JSON format and syncs to all updates of the data to all clients listening to the data . It abstracts you from all complexity that is needed to setup and scale any database . I will not recommend firebase where you have lot of complex scenarios where aggregation of data is needed .(Queries that need SUM/AVERAGE kind of stuff ) . Though this is recently achievable using Firebase functions . Modeling data in Firebase is tricky . But it is the best way to get you started instantaneously . MongoDB is a database. This give you lot of powerful features. But MongoDB when installed in any platform you need to manage it by yourself .

When i try to choose between Firebase or MongoDB(or any DB ) . I try to answer the following .

  1. Are there many aggregation queries that gets executed .(Like in case of reporting tool or BI tool ) . If Yes dont go for Firebase
  2. Do i need to perform lot of transaction . (If yes then i would not like to go with firebase) (Tranactions are somewhat easy though after introduction of functions but that is also a overhead if lot of transactions needs to be maintained)
  3. What timeline do i have to get things up and running .(Firebase is very easy to setup and integrate ).
  4. Do i have expertise to scale up the DB and trouble shoot DB related stuffs . (Firebase is more like SAAS so no need to worry about scaleability)
suvankar bose
  • 291
  • 2
  • 12
  • My understanding is that you are not happy with firebase aggregation queries. However this is not what your point (1) says. Could you give an example where aggregation query is not easy as you say (or as I understand you say)? – NoChance Jan 31 '22 at 22:34
16

In my experience, working with Firebase is a huge advantage if you are trying to do user management, database, messaging sort of app since all of these features are already well integrated.

Like others have said, if you're just focused on the database/querying aspect, stick to mongo.

Nam Kim
  • 229
  • 2
  • 10
16

Firebase provides some good features like real time change reflection , easy integration of authentication mechanism , and lots of other built-in features for rapid web development. Firebase, really makes Web development so simple that never exists. Firebase database is a fork of MongoDB.

What's the advantage of using Firebase over MongoDB?

You can take advantage of all built-in features of Firebase over MongoDB.

mnhmilu
  • 2,327
  • 1
  • 30
  • 50