I am familiar with MongoDB because I recently tested MongoDB. MongoDB is still simple, and I have mastered a lot of content in just one week. It is much easier than other databases.
I installed:
MongoDB version 2.0.8
System: 64-bit Ubuntu 12.04
Let's show him my table structure first. [Oh sorry, Mongo is called a set]
As you can see, I try my best to simulate real-life scenarios. This is a person's entity. He has a basic manId, manName, friend [myFriends], a favorite fruit [fruits], and each fruit has a favorite weight.
What's bad is that you still see a "_ class" field? Because I am a Java developer and I also like to use Spring, I chose the Spring Data Mongo Class Library [which is also a framework, but I don't think so].
Many people are getting bored with Spring. Yes, Spring is ambitious. He almost wants to monopolize everything in Java. There is no way I can't do without Spring, so that I don't need to learn any other frameworks. I have learned a lot about Spring, such as Spring Security, Spring Integration, and Spring Batch... Without inventing the wheel, he has already provided many programming scenarios. I have used those scenarios to solve many problems in my work and make my work very efficient. So I learned more about it. Spring Data Mongo encapsulates the mongodb java driver and provides the same programming style as SpringJDBC/Template.
See: http://static.springsource.org/spring-data/data-mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoTemplate.html
Let's go directly to MongoDB.
When I was testing Mongo, my colleague and I still wrote less than half of the index. He wanted to query the maximum value of a field. After finding the result for half a day, the document did not find the function about max. I am also wondering if this is a regular function. Why not? Later, I checked the information and confirmed that Mongo does not provide direct max and min functions. However, this can be achieved through indirect [sort and limit.
To query the maximum value, we only need to sort the result set in descending order and take the first value.
For example, in my example, I want to obtain the largest person of age in the collection.
Db. person. find ({}). sort ({"age":-1}). limit (1)
If you want the youngest person, you only need to change sort to {"age": 1.
Of course, we use sort, Which is okay for a small number of documents. If you need to create an index for age for a large amount of data, otherwise this operation will take a long time.