Page 1 of 1
Looking for help with MongoDB
Posted: Tue Dec 10, 2013 8:03 pm
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

Re: Looking for help with MongoDB
Posted: Tue Dec 10, 2013 9:05 pm
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.
Re: Looking for help with MongoDB
Posted: Tue Dec 10, 2013 9:11 pm
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

Re: Looking for help with MongoDB
Posted: Tue Dec 10, 2013 9:29 pm
by Jackolantern
Awesome!
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.
Re: Looking for help with MongoDB
Posted: Wed Dec 11, 2013 5:50 am
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.
Re: Looking for help with MongoDB
Posted: Wed Dec 11, 2013 5:09 pm
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.
Re: Looking for help with MongoDB
Posted: Wed Dec 11, 2013 5:41 pm
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

Re: Looking for help with MongoDB
Posted: Wed Dec 11, 2013 7:01 pm
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.
Re: Looking for help with MongoDB
Posted: Wed Dec 11, 2013 11:47 pm
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.