Looking for help with MongoDB

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Looking for help with MongoDB

Post by OldRod »

I'm needing some help with MongoDB

Specifically, I am looking to see how I can set it up to work in my development environment. I am currently using WAMP on my local machines. I have my MySQL databases hosted on a Bluehost site and all my PHP/HTML5/CSS/JS development is synchronized through DropBox so I can work with WAMP on any machine, yet still get access to my databases (which don't really work over Dropbox)

From what I can see BlueHost does not support MongoDB, but is it possible to install it and use it there somehow? Or is there another option that would allow me to keep working like I am and use MongoDB instead of MySQL?

Also... are there any really good MongoDB tutorials out there? All I'm seeing are pretty much just how to install it. Nothing that useful.

Thanks :)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Looking for help with MongoDB

Post by Jackolantern »

There are quite a few ways to actually connect to a cloud database running MongoDB. For example, you could use a database-as-a-service provider like MongoLab. The 0.5 GB storage they give you for free should be plenty for a while.

As for tutorials, here is what looks like a pretty nice tutorial for using mongo with PHP. I have not gone through it, though, as I use mongo with node, and have never tried using it with PHP.
The indelible lord of tl;dr
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: Looking for help with MongoDB

Post by OldRod »

Thanks, Jack. I'll check those out.

I'd run across that tutorial before, but for some reason it didn't get bookmarked. It is now :)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Looking for help with MongoDB

Post by Jackolantern »

Awesome! :cool:

Also, I highly suggest to simply learn how to use mongo from the shell first, before trying to use it in a programming language. It is similar in some ways and quite different in other ways than typical databases, so it is helpful if you have a general idea of how it works before adding a language-specific driver library on top of that. First start with the interactive Try it Out program, and then move into some of the basic pages in the documentation until you can do any query you need to, all the CRUD operations, etc.
The indelible lord of tl;dr
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Looking for help with MongoDB

Post by a_bertrand »

If I shall add a bit of info too... Before jumping on the MongoDB bandwagon, I would really consider WHY you would do it:

1) PHP is maybe not the best language for it? No clues never tested the PHP / MongoDB together, so I can't tell it. I always used node.js with MongoDB and even then my experience are really limited compared to normal SQL databases. But before considering MongoDB you should check if it works well with PHP (I'm pretty sure it does).
2) Why MongoDB and not MySQL? Do you have unrelated data to store and access? Complex objects to store and restore? If yes MongoDB can be an option. On the other side, if you want usual SQL stuff, with relations between tables and such, then MongoDB is NOT the way to go.
3) As you discover, not all hosting are offering it, remote DB is doable, but will be MUCH slower. For a production system or something you really plan to use, I would not consider it an option.

Finally, if it's for your own tests, install your beloved xampp / wampp on your PC and then install as well MongoDB on it, you can test all locally and see how it goes and if it brings something. MongoDB will not replace MySQL it is simply a different tool for different needs.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Looking for help with MongoDB

Post by hallsofvallhalla »

I agree with a_bertrand that Mongo may not be the best solution as it depends on what you are trying to accomplish. MySQL works perfectly well with non realtime games. My main reason to use Mongo was because I am using Nodejs on the back end and the connectivity is so much easier. I also have built a MASSIVE map, over 12 million locations, and mongo can handle that better for the way i will be loading.

Now if you are wanting to use it to learn it and/or are using NodeJs or mainly JS then you could rent a VPS for around $5 a month and host the web server and mongo. Installing the web setup on a VPS is very easy. Especially on Ubuntu. You can then use filezilla and putty to connect to it and transfer files and such.
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: Looking for help with MongoDB

Post by OldRod »

I will be using Node.js for this as I rebuild it from scratch. That's why I was looking at Mongo. I just need time... and tutorials to study :)
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Looking for help with MongoDB

Post by hallsofvallhalla »

ah well then good choice :)

Mongo seems daunting at first but once you get into it it is really simple. Even more simple than SQL.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Looking for help with MongoDB

Post by Jackolantern »

Or just use a nice ORM like Waterline, and you can interact with your data store as if it was an object:

Creating a data model:

Code: Select all

// Person.js
var Person = {
  attributes: {
    firstName: 'STRING',
    lastName: 'STRING',
    age: {
      type: 'INTEGER',
      max: 150,
      required: true
    }
    birthDate: 'DATE',
    phoneNumber: {
      type: 'STRING',
      defaultsTo: '111-222-3333'
    }
    emailAddress: {
      type: 'email', // Email type will get validated by the ORM
      required: true
    }
  }
};

module.exports = Person;
And then to interact with it, just find the object you need, change it and save:

Code: Select all

// Lookup a user
User.findOne(1).done(function(err, user) {

  // we now have a model with instance methods attached
  // update an attribute value
  user.email = 'foo.bar@gmail.com';

  // save the updated value
  user.save(function(err) {
    // value has been saved
  });

});
Waterline works the exact same way whether you are using MySQL, MongoDB, or others, so you can change the back-end with no change to your model code.

And I also highly recommend the whole web framework that Waterline is a part of, Sails.js.
The indelible lord of tl;dr
Post Reply

Return to “General Development”