-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing MongoDB #16
Comments
@alonttal You did a great job! |
I started reading more about the MongoDB (since it seems as the most suitable DB) - I agree with a argument I read that working directly with the Java driver it’s quite low-level - we have to do a lot of taking things out of our domain objects and poking them into MongoDB-shaped DBObjects, and vice-versa (it can be implemented with an adapter design pattern but it is still a "low-level" work). The extra work has been done before by others. There are tools that use the MongoDB Java Driver at their core to interact with MongoDB. They provide a high-level abstraction for converting the domain objects into MongoDB documents, whilst also giving you a way to get to the underlying driver as well in case you need to use it at a lower level. One of them is Spring Data. Spring Data is an ODM (Object Document Mapper). This supports traditional relational and non-relational databases, including MongoDB and since we are going to use Spring in our application, this should be a familiar way to work. In addition, there’s a lot of really great documentation, including a Getting Started guide with example code - I will summarize it (the section of working with the DB). |
I collected the information I read and wrote a ~20 pages tutorial about: MongoDB and the integration of it with Java (with Java Driver and Spring Data) - The tutorial (which is mostly copy-pasted) covers the core ideas of the above issues alongside practical information relevant to our interests (e.g handling geolocation data, installing on Amazon Linux platform…) The tutorial includes information about -
The tutorial is attached as a pdf file (the version attached here is the first one and it will be updated during the work). |
wow @OrAbramovich great work !! thanks ! |
Thanks! |
a short comparision between MySQL and MongoDB |
moved this tutorial to "Guides" section in Wiki |
Introduction to MongoDB
Why MongoDB?
document database is a database designed to store data in a semi-structure format, typically in JSON or XML. In MongoDB, the information is stored in JSON format.
How Does MongoDB Stores Data?
Official Drivers
MongoDB is available in C++, C#, Java, Node.js and more…
See: https://docs.mongodb.com/ecosystem/drivers/
Data Modeling
As already said, the data is saved in JSON format and documents in the same collection do not need to have the same structure.
For example, let's write a small collection of apartments:
As we can see, all the information can be stored in a single collection, while our RDBMS fellow needs: a table to store apartments data, a table to store comments, and a table to store tags. Was it convincing enough?
Some Features
db.COLLECTION_NAME.insert(document)
db.COLLECTION_NAME.update(CRITERIA, UPDATED_VALUE)
Delete document: all documents with CRITERIA will be removed. Using justOne() will remove the first occurrence with CRITERIA.
db.COLLECTION_NAME.remove(CRITERIA)
db.COLLECTION_NAME.remove(CRITERIA).justOne()
db.COLLECTION_NAME.find([CRITERIA])
Db.COLLECTION_NAME.find().sort({"FIELD_NAME":1})
In order to do so, we will write:
db.apartments.aggregate([{$group : {_id : "$_id", min_price : {$min : "$price"}}}])
mongodump
@OrAbramovich comment on MongoDB:
The text was updated successfully, but these errors were encountered: