MongoMongo is an Object-Document-Mapper (ODM) for MongoDB written in Java.
The philosophy of MongoMongo is to provide a familiar API to Java developers who have been using ActiveORM or Hibernate, while leveraging the power of MongoDB's schemaless and performant document-based design,dynamic queries, and atomic modifier operations.
Sample code:
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(); } }
You can put assotiation,storage declare,index creating ,alias filed in static block of model,all can done by a method calling. Properties and Getter/Setter methods are optional.In sample code,pojo propertes declared make you know tha how many fields should be put in mongo collection.
There are already some ODM like morphia,SpringData.We can see diffrences bettween MongoMongo
SpringData for MongoDB:
public static void main( String[] args ) { MongoOperations mongoOps = new MongoTemplate(new Mongo(), "mydb"); Person person = new Person(); person.setName("Joe"); person.setAge(10); mongoOps.insert(person); log.info(mongoOps.findOne(new Query(Criteria.where("name").is("Joe")), Person.class)); }
Actually,most of java ODM operate model like this. Introduce Criteria Object for Query constructing, and Query Object for query. You also should tell
MongoOperations who do you want to operate(here is Person.class). It's bit tough for index,alias,validation configuration,normaly they will put this infomation
on annotation,or som Configuration Object. MongMongo put all these in static block,using static method to declare,convenient,clear and easy to manager.
MongoMongo code:
public static void main( String[] args ) { Person person = Person.create(map("name","Joe","age",34)); person.save(); log.info(Person.where(map("name","Joe")).singleFetch()); }
MongoMongo's query is similary with ActiveRecord in rails.
Blog blog = Blog.where(map("active",true)).in(map("id",list(1,2,3))).singleFetch();
Normally i will write like this:
public class Blog extends Document { public Criteria active(){ return where(map("active",true)); } }
then you can call it like this:
List<Blog> blogs = Blog.active().where(map("userName","jack")).fetch();
If you have used ActiveORM,then you will be familiar with MongMongo.
You also can MongoDB Java Driver directly like this:
TTUser.collection().find(new BasicDBObject("tagName","cool"));
you can call static method collection() to get DBCollection Object.
Try MongoMongo according to this article: 5 steps to run a application on MongoMongo
相关推荐
mongodb-spark官方连接器,运行spark-submit --packages org.mongodb.spark:mongo-spark-connector_2.11:1.1.0可以自动下载,国内网络不容易下载成功,解压后保存到~/.ivy2目录下即可。
mongodb-windows安装包: mongodb-compass-1.31.2-win32-x64.msi 打开直接安装
Spring集成MongoDB官方指定jar包:spring-data-mongodb-1.4.1.RELEASE.jar
赠送jar包:mongodb-driver-core-4.2.3.jar; 赠送原API文档:mongodb-driver-core-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-core-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-core-4.2.3....
赠送jar包:mongodb-driver-sync-4.2.3.jar; 赠送原API文档:mongodb-driver-sync-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-sync-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-sync-4.2.3....
MongoDB Community Server(mongodb-org-mongos-5.0.4-1.el7.x86_64.rpm)适用于RedHat / CentOS 7.0 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。...
赠送jar包:mongodb-driver-core-4.2.3.jar; 赠送原API文档:mongodb-driver-core-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-core-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-core-4.2.3....
MongoDB Community Server(mongodb-org-shell-5.0.4-1.el7.x86_64.rpm)适用于RedHat / CentOS 7.0 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 ...
sql-to-mongo-db-query-converter sql-to-mongo-db-query-converter可帮助您基于SQL中提供的查询为MongoDb构建查询。玛文向com.github.vincentrussell:sql-to-mongo-db-query-converter添加依赖...
mongodb spark连接器,适用版本spark2.1.X ,Scala2.11.X, java 6 or later,mongodb 2.6 or later,请根据上面的版本选择,不然会报各种错误
pyspark2.3.0,scala2.11,连接mongodb的jar包,注意对应的版本
MongoDB mongo-go-driver和变更流示例 2020年1月9日:替换为go.mongodb.org/mongo-driver(v1.2.0) 2019/02/25:替换为go.mongodb.org/mongo-driver(v1.0.0-rc1) 使用MongoDB Change Streams实现。 mongo-go-...
mongodb-async-driver-2.0.1 jar包
mongodb-org-shell ,包含mongo shell。 mongodb-org-tools ,包含以下MongoDB工具:mongoimport bsondump,mongodump,mongoexport,mongofiles,mongorestore,mongostat和mongotop。 docker build --rm -t ...
java和mongodb连接,需要mongodb-driver,您还必须下载其依赖项: bson和 mongodb-driver-core》》3个包: mongodb-driver-3.8.2.jar; bson-3.8.2.jar; mongodb-driver-core-3.8.2.jar
MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系...
MongoDB Community Server(mongodb-org-server-5.0.4-1.el7.x86_64.rpm)适用于RedHat / CentOS 7.0 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。...
【MongoDB C Driver 1.14.0】--截止2019.6.26的最新版本 1、编译好的Mongodb C语言库,包含lib、dll、include,版本1.14.0,32位的 2、包含文件的清单: ...\mongo-c-driver\bin ...\mongo-c-driver\include ...\...
fait-it / mongodb-bundle 官方驱动程序库的捆绑服务集成(packagist上的 ) 安装 首先,您需要通过composer要求此库: composer require facile-it/mongodb-bundle 然后,在AppKernel类上启用该捆绑包: // app...