Mongmongo is a Java-written ODM framework, making the operation of MongoDB more convenient.
Mongomongo strives to provide Java developers with an operational API similar to Activeorm or hibernate, and retains MongoDB's schemaless,document-based design, dynamic query, and atomic modification operations. Of course, you can easily bypass Mongomongo and use the Java Driver functionality provided by the native.
The following is a sample code:
[Java] View plain copy public class blog extends document { static { storein ("blogs"); hasmanyembedded ("Articles", new options (map options.n_kclass, Article.class )); //create index index (Map ("Blogtitle", -1), map (unique,true)); //validate uerName field Validate ("UserName ", Map (Length,map minimum,5 )); } //association related public associationembedded articles () {throw new Autogeneration ();} private String userName; private string blogtitle; } public class article extends document { static { belongstoembedded ("blog", New options (Map ( options.n_kclass, blog.class )) ; } public associationembedded blog () {throw new autogeneration (); private String title; private String body; } public class usage{ public static void main (String[] args) { blog blog = blog.where (Map ("UserName", "Sexy java")). In (Map ("id", List (1,2,3)). Singlefetch (); blog.articles (). Build (Map ("title", "i am Title "," Body "," i am body "); blog.save (); } }
We can see that this is a typical congestion model. associating, storing, creating indexes, setting aliases, and so on, simply call a function in the static block to achieve it. If you use some dynamic language, you will find that this method-level declarative syntax is very popular and very comfortable to write.
In fact, there are many frameworks related to MongoDB, so the advantages of Mongomongo. We can simply make a comparison of the code at a glance.
For example, Springdata for MongoDB, the typical operation is as follows:
[Java]