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 打开直接安装
赠送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....
Spring集成MongoDB官方指定jar包:spring-data-mongodb-1.4.1.RELEASE.jar
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....
Mongo-Connector是一个强大的工具,用于将MongoDB的数据同步到其他数据存储系统,如Elasticsearch或Solr。在本案例中,我们关注的是版本2.3.0,它专为pyspark2.3.0和Scala2.11构建。这个版本确保了与特定Spark和...
官网下载的:mongodb-org-server-4.4.0-1.el7.x86_64.rpm 官网速度慢,此处放一份。 下载地址: https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-server-4.4.0-1.el7.x86_64.rpm 无...
sql-to-mongo-db-query-converter sql-to-mongo-db-query-converter可帮助您基于SQL中提供的查询为MongoDb构建查询。玛文向com.github.vincentrussell:sql-to-mongo-db-query-converter添加依赖...
MongoDB是一个流行的开源、文档型数据库系统,而`mongo-java-driver`是官方提供的Java API,允许开发者在Java应用程序中执行各种数据库操作,如读取、写入、查询等。 在本例中,我们讨论的是`mongo-java-driver`的...
win7环境下,使用vs2017编译的MongoDB-c-driver 和MongoDB-cxx-driver。 下载之后可以直接放入C++工程中使用。 版本信息: mongo-c-driver-1.13.0, mongo-cxx-driver-r3.4.0
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
本资源内含4个文件:mongo-java-driver-3.9.1.jar,MongoDB JDBC驱动包。mongo-java-driver-3.9.1-sources.jar,MongoDB JDBC驱动源代码包。mongo-java-driver-3.9.1-javadoc.jar,MongoDB JDBC驱动JAVA API文档包。...
libraryDependencies += "org.mongodb.scala" %% "mongodb-scala-driver" % "4.2.0" // 使用最新版本号 ``` 一旦依赖添加成功,我们就可以开始编写 Scala 代码来连接 MongoDB 数据库了。`mongo-scala-driver` 提供...
mongo-java-driver是java语言操作mongodb数据库的驱动包,封装了针对mongodb的相关操作 代码案例: 数据库和集合操作 连接MongoDB服务: MongoClient mongoClient = new MongoClient(host, port); 连接数据库: ...
在使用过程中,你可以利用MongoDB的管理工具如`mongodump`和`mongorestore`进行数据备份和恢复,`mongoexport`和`mongoimport`用于数据导入导出,以及`mongostat`和`mongotop`来监控数据库性能。 总的来说,MongoDB...
MongoDB Community Server(mongodb-org-server-5.0.8-1.el7.x86_64.rpm)适用于RedHat / CentOS 7.0 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。...
mongo-java-driver-3.4.3.jar 是 MongoDB 官方为 Java 开发者提供的 Java 驱动程序的一个特定版本(3.4.3)。这个 JAR 文件包含了与 MongoDB 数据库进行交互所需的类和接口,允许 Java 应用程序连接到 MongoDB 实例...
mongodb-org-shell ,包含mongo shell。 mongodb-org-tools ,包含以下MongoDB工具:mongoimport bsondump,mongodump,mongoexport,mongofiles,mongorestore,mongostat和mongotop。 docker build --rm -t ...