{"id":25776134,"url":"https://github.com/fakemongo/fongo","last_synced_at":"2025-02-27T06:05:38.725Z","repository":{"id":11639662,"uuid":"14143348","full_name":"fakemongo/fongo","owner":"fakemongo","description":"faked out in-memory mongo for java","archived":false,"fork":true,"pushed_at":"2020-11-09T13:24:00.000Z","size":3654,"stargazers_count":523,"open_issues_count":82,"forks_count":159,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-11-17T12:52:51.944Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"foursquare/fongo","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fakemongo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-05T14:22:05.000Z","updated_at":"2024-08-24T02:36:50.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/fakemongo/fongo","commit_stats":null,"previous_names":[],"tags_count":67,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakemongo%2Ffongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakemongo%2Ffongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakemongo%2Ffongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakemongo%2Ffongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fakemongo","download_url":"https://codeload.github.com/fakemongo/fongo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240987435,"owners_count":19889333,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-27T06:01:18.390Z","updated_at":"2025-02-27T06:05:38.717Z","avatar_url":"https://github.com/fakemongo.png","language":"Java","funding_links":[],"categories":["测试"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/fakemongo/fongo.svg?branch=master)](https://travis-ci.org/fakemongo/fongo)\n\n# fongo\n\nFongo is an in-memory java implementation of MongoDB. It intercepts calls to the standard mongo-java-driver for \nfinds, updates, inserts, removes and other methods. The primary use is for lightweight unit testing where you\ndon't want to spin up a `mongod` process.\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.fakemongo/fongo/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.fakemongo/fongo/) ![License Apache2](https://go-shields.herokuapp.com/license-apache2-blue.png)\n\n## Usage\nAdd dependency to your project:\n\n### If you use 3.X drivers (async included)\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.fakemongo\u003c/groupId\u003e\n  \u003cartifactId\u003efongo\u003c/artifactId\u003e\n  \u003cversion\u003e2.1.0\u003c/version\u003e\n  \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n[Other dependency management](http://search.maven.org/#artifactdetails|com.github.fakemongo|fongo|2.1.0)\n\n### If you use 2.X drivers (this branch *fongo-drivers-2.x*) will be deprecated soon\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.fakemongo\u003c/groupId\u003e\n  \u003cartifactId\u003efongo\u003c/artifactId\u003e\n  \u003cversion\u003e1.6.5\u003c/version\u003e\n  \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n[Other dependency management](http://search.maven.org/#artifactdetails|com.github.fakemongo|fongo|1.6.5)\n\n\n*Alternatively: clone this repo and build the jar: `mvn package` then copy jar to your classpath*\n\nUse in place of regular `com.mongodb.Mongo` instance:\n\n```java\nimport com.github.fakemongo.Fongo;\nimport com.mongodb.BasicDBObject;\nimport com.mongodb.DB;\nimport com.mognodb.DBCollection;\n...\nFongo fongo = new Fongo(\"mongo server 1\");\n\n// once you have a DB instance, you can interact with it\n// just like you would with a real one.\nDB db = fongo.getDB(\"mydb\");\nDBCollection collection = db.getCollection(\"mycollection\");\ncollection.insert(new BasicDBObject(\"name\", \"jon\"));\n```\n\n## Scope\n\nFongo doesn't implement all MongoDB functionality. Most query and update syntax is supported. \nGridfs and capped collections are not supported.\nMapReduce is in minimal way but will be enhanced soon.\n\n * `$near` can be used\n * `$geoWithin` can be used with $box for now.\n\n## Implementation Details\n\nFongo depends on [Objenesis](http://objenesis.org/) to hijack the `com.mongodb.MongoClient` class. It has a \"provided\" dependency on the mongo-java-driver and was tested with *2.13.0*\nand *3.0.1*.\nIt also has a \"provided\" dependency on sl4j-api for logging. If you don't already have sl4j in your project, you can add a maven dependency to the logback implementation like this:\n\n```xml\n\u003cdependency\u003e \n  \u003cgroupId\u003ech.qos.logback\u003c/groupId\u003e\n  \u003cartifactId\u003elogback-classic\u003c/artifactId\u003e\n  \u003cversion\u003e1.1.7\u003c/version\u003e\n  \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nFongo should be thread safe. All read and write operations on collections are synchronized. It's pretty coarse, but\nshould be good enough for simple testing. Fongo doesn't have any shared state (no statics). Each fongo instance is completely independent.\n\n## Usage Details\n\n```java\n// Fongo instance methods\n\n// get all created databases (they are created automatically the first time requested)\nCollection\u003cDB\u003e dbs = fongo.getUsedDatabases();\n// also\nList\u003cString\u003e dbNames = fongo.getDatabaseNames();\n// also\nfongo.dropDatabase(\"dbName\");\n\n// get an instance of the hijacked com.mongodb.Mongo\nMongo mongo = fongo.getMongo();\n```\nIf you use Spring, you can configure fongo in your XML configuration context:\n\n```xml\n\u003cbean name=\"fongo\" class=\"com.github.fakemongo.Fongo\"\u003e\n    \u003cconstructor-arg value=\"InMemoryMongo\" /\u003e\n\u003c/bean\u003e\n\u003cbean id=\"mongo\" factory-bean=\"fongo\" factory-method=\"getMongo\" /\u003e\n\n\u003cmongo:db-factory id=\"mongoDbFactory\" mongo-ref=\"mongo\" /\u003e\n\n\u003c!-- localhost settings for mongo --\u003e\n\u003c!--\u003cmongo:db-factory id=\"mongoDbFactory\" /\u003e--\u003e\n\n\u003cbean id=\"mongoTemplate\" class=\"org.springframework.data.mongodb.core.MongoTemplate\"\u003e\n    \u003cconstructor-arg ref=\"mongoDbFactory\"/\u003e\n\u003c/bean\u003e\n```\n\n## Junit\n\nIf you use JUnit in your project, you can use Rule to instantiate a `Fongo` object :\n\n```java\n@Rule\npublic FongoRule fongoRule = new FongoRule();\n```\n\nIf you need, you can easily switch to your real MongoDB server (on localhost for now).\n\n```java\n@Rule\npublic FongoRule fongoRule = new FongoRule(true);\n```\n\nWARNING : In this case, the database WILL BE DROPPED when test is finish.\nSo, use a random database name (e.g. UUID), BUT NOT your real database.\n\nYou can specify the version of the database with :\n\n```java\n@Rule\npublic FongoRule fongoRule = new FongoRule(new ServerVersion(2, 6));\n```\n\nIn this case, the drivers didn't handle queries with the same way.\n\n## Junit (async drivers)    \n\nIf you use JUnit in your project, you can use Rule to instantiate a `Fongo` object :\n\n```java\n@Rule\npublic FongoAsyncRule fongoAsyncRule = new FongoAsyncRule();\n```\n\nIf you need, you can easily switch to your real MongoDB server (on localhost for now).\n\n```java\n@Rule\npublic FongoAsyncRule fongoAsyncRule = new FongoAsyncRule(true);\n```\n\nWARNING : In this case, the database WILL BE DROPPED when test is finish.\nSo, use a random database name (e.g. UUID), BUT NOT your real database.\n\nYou can specify the version of the database with :\n\n```java\n@Rule\npublic FongoAsyncRule fongoAsyncRule = new FongoAsyncRule(new ServerVersion(2, 6));\n```\n\nIn this case, the drivers didn't handle queries with the same way.\n\n\n## Text Search Simulation\nFongo simulates [text search](http://docs.mongodb.org/manual/reference/command/text/) now.\nThe results of text search are quite similar to real, but not exactly.\n\n### Next features are supported:\n* Plain words search\n* Search strings\n* Negated words\n* Projections in search query\n* Limits\n\n### Fongo text search simulation does not support:\n* Languages (including language-specific stop words)\n* Filter (maybe in future)\n* Weights in text index (we plan to support them in future)\n\n### Limitations, Differences:\n* Only [text command](http://docs.mongodb.org/manual/reference/command/text/) search is supported. We will support [find query with $text operator](http://docs.mongodb.org/master/reference/operator/query/text/) probably in future.\n* Scores in returned results are not always the same as the real Mongo's scores.\n* Only one field can be indexed as text field now. This limitation will be removed soon.\n\n### Usage example of the text search simulation:\n```java\n    @Test\n    public void findByTextTest() {\n    //....\n    //Define index:\n    collection.createIndex(new BasicDBObject(\"myTextFieldToIndex\", \"text\"));\n\n    DBObject textSearchCommand = new BasicDBObject(\"search\", \"my search \\\"my phrase\\\" -without -this -words\");\n\n    //Search Command\n    DBObject textSearchResult = collection.getDB()\n            .command(new BasicDBObject(\"collection\", new BasicDBObject(\"text\", textSearchCommand)));\n\n    //Make your assertions\n    //....\n\t}\n```\n\n## Todo\n\n* more testing\n* complete compatibility with Jongo\n\n## Reporting Bugs and submitting patches\n\nIf you discover a bug with fongo you can file an issue in github. At the very least, please include a complete description of the problem with steps to reproduce.\nIf there were exceptions thrown, please include the complete stack traces. If it's not easy to explain the problem, failing test code would be helpful.\nYou can fork the project and add a new failing test case. \n\nIt's even better if you can both add the test case and fix the bug. I will merge pull requests with test cases and add \nyour name to the patch contributors below. Please maintain the same code formatting and style as the rest of the project.\n\n## Changelog\n\nVersion 2.1.0 include compatibility with 3.X async driver version.\nVersion 2.0.0 break compatibility with 2.X driver version.\nVersion 1.6.0 break compatibility with 2.12.X driver version.\n\n## Original Author\n* [Jon Hoffman](https://github.com/hoffrocket)\n\n## Patch Contributers\n* [Guido García](https://github.com/palmerabollo)\n* [rid9](https://github.com/rid9)\n* [aakhmerov](https://github.com/aakhmerov)\n* [Eduardo Franceschi](https://github.com/efranceschi)\n* [Tobias Clemson](https://github.com/tobyclemson)\n* [Philipp Knobel](https://github.com/philnate)\n* [Roger Lindsjö](https://github.com/rlindsjo)\n* [Vadim Platono](https://github.com/dm3)\n* [grahamar](https://github.com/grahamar)\n* [Boris Granveaud](https://github.com/bgranvea)\n* [Philipp Jardas](https://github.com/phjardas)\n* [Sergey Passichenko](https://github.com/serj-de-sudden)\n* [William Delanoue](https://github.com/twillouer)\n* [Juan F. Codagnone](https://github.com/jcodagnone)\n* Anton Bobukh\n* [Matthew Reid](https://github.com/drei01)\n* [jasondemorrow](https://github.com/jasondemorrow)\n* [lldata](https://github.com/lldata)\n* [renej-github](https://github.com/renej-github)\n* [mathieubodin](https://github.com/mathieubodin)\n* [Alex Art](https://github.com/elennaro)\n* [htmldoug](https://github.com/htmldoug)\n* [antonbobukh](https://github.com/antonbobukh)\n* [Alban Dericbourg](https://github.com/adericbourg)\n* [louisnerys](https://github.com/louisnerys)\n* [Changgeng Li](https://github.com/changgengli)\n* [Nils Meder](https://github.com/nilstgmd)\n* [Liran Moysi](https://github.com/liranms)\n* [Kong TO](https://github.com/newlight77)\n* [tomdearman](https://github.com/tomdearman)\n* [James Jory](https://github.com/james-jory)\n* [Riaz Ahmed](https://github.com/riyyaz)\n* [Martin W. Kirst](https://github.com/nitram509)\n* [LiBe](https://github.com/libetl)\n* [Vladimir Shakhov](https://github.com/bogdad)\n* [Guy de Pourtalès](https://github.com/gdepourtales)\n* [Heng-Scheng Chuang](https://github.com/ddchengschengc)\n* [Guillermo Campelo](https://github.com/guicamest)\n* [Arthur Cinader](https://github.com/acinader)\n* [Jimmy Royer](https://github.com/jimleroyer)\n* [Akbashev Alexander](https://github.com/Jimilian)\n* [Ben](https://github.com/BenRomberg)\n* [Daniil Gitelson](https://github.com/daniilguit)\n* [Mark Crossfield](https://github.com/mrmanc)\n* [Rory Douglas](https://github.com/worrel)\n* [Georg Meyer](https://github.com/scho)\n* [Igor](https://github.com/ilaborie)\n* [Corey Vaillancourt](https://github.com/coreyjv)\n* [Eric Karge](https://github.com/e-karge)\n* [Matthias Egli](https://github.com/MatthiasEgli)\n* [Yaniv Oliver](https://github.com/yanivoliver)\n* [Yunchi Luo](https://github.com/mightyguava)\n* [Avihai Berkovitz](https://github.com/aciduck)\n* [Kollivakkam Raghavan](https://github.com/krraghavan)\n* [Ann Katrin Gagnat](https://github.com/akgagnat)\n* [Nicola Viola](https://github.com/nicolaViola)\n* [Michael Childs](https://github.com/mchildspelco)\n* [Dmitri Maksimov](https://github.com/mcdimus)\n* [Enrico Pelizzon](https://github.com/theimplementer)\n* [Krzysztof Sukienniczak](https://github.com/krs)\n* [zigzago](https://github.com/zigzago)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffakemongo%2Ffongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffakemongo%2Ffongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffakemongo%2Ffongo/lists"}