MongoDB is document oriented but has many comparable concepts to traditional SQL/RDBMS solutions.
If you have used MySQL or Oracle here is a good guide to similar processes in MongoDB:
You can see a trend here. Where possible, MongoDB tries to follow the terminology of MySQL. They do this with console commands as well. If you are used to using MySQL, where possible, MongoDB tries to make the transition a bit less painful.
SQL operations versus MongoDB operationsMongoDB queries are similar in concept to SQL queries and use a lot of the same terminology. There is no special language or syntax to execute MongoDB queries; you simply assemble a JSON object. The MongoDB site has a complete set of example queries done in both SQL and MongoDB JSON docs to highlight the conceptual similarities. What follows is several small listings to compare MongoDB operations to SQL.
InsertSQLINSERT INTO CONTACTS (NAME, PHONE_NUMBER) VALUES('RICK HIGHTOWER','520-555-1212') MongoDBdb.contacts.insert({name:'RICK HIGHTOWER',phoneNumber:'520-555-1212'}) SelectsSQLSELECT name, phone_number FROM contacts WHERE age=30 ORDER BY name DESC MongoDBdb.contacts.find({age:30}, {name:1,phoneNumber:1}).sort({name:-1}) SQLSELECT name, phone_number FROM contacts WHERE age>30 ORDER BY name DESC MongoDBdb.contacts.find({age:{$gt:33}}, {name:1,phoneNumber:1}).sort({name:-1}) Creating indexesSQLCREATE INDEX contact_name_idx ON contact(name DESC) MongoDBdb.contacts.ensureIndex({name:-1}) UpdatesSQLUPDATE contacts SET phoneNumber='415-555-1212' WHERE name='Rick Hightower' MongoDBdb.contacts.update({name:'Rick Hightower'}, {$set:{phoneNumber:1}}, false, true) Additional features of noteMongoDB has many useful features like Geo Indexing (How close am I to X?), distributed file storage, capped collection (older documents auto-deleted), aggregation framework (like SQL projections for distributed nodes without the complexities of MapReduce for basic operations on distributed nodes), load sharing for reads via replication, auto sharding for scaling writes, high availability, and your choice of durability (journaling) and/or data safety (make sure a copy exists on other servers). If you would like to learn more about MongoDB consider the following resources:
|
Mammatus Blog >