Skip to content

ODM Allowing to modify documents in the Mongo db very quickly and easily with class fields and optimized reflection

Notifications You must be signed in to change notification settings

360matt-archives/FastMongo-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

💥 FastMongo v2 BCH compliance

ORM Allowing to modify documents in the Mongo db very quickly and easily with class fields and optimized reflection.

This documentation is incomplete since v2.3 was released.

⁉️ Why use this API ?

  • 💡 As simple as possible, it is easy to learn
  • ⌛ Its use is very fast, even the migration
  • 🎨 It is customizable, you can define many behavior in this API
  • 💾 Your data is better structured
  • 🚦 You can develop your project and your structure
  • ♻️ Very light, my code represents only 11 KB (against 17 KB in v1)

🔥 What's new in v2 ?

  • ⌛ Better performance
  • ⌛ Better reflection system (with cache)
  • ♻️ Less class, less instantiation
  • ♻️ Generic Type removed
  • ♻️ Less code needed, much simpler
  • 👥 Can now use multiple (infinite?) database at the same time

🔗 Dependencies:

  • I only use the official Mongo driver in the latest version (4.2.3)

Maven

<repositories>
    <repository>
        <id>sonatype</id>
        <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>
<dependency>
    <groupId>io.github.360matt</groupId>
    <artifactId>FastMongo-v2</artifactId>
    <version>2.3.1-SNAPSHOT</version>
</dependency>

💪 Benchmarks:

With FX8300 overclocked 4Ghz / DDR3 overclocked 1600Mhz.
With 500_000 documents.
Action: load (doc->field), modify (field) and save (field->doc).

Time elapsed: 160ms.
Every document: 0,000318ms (= 318ns)

⭐ Beginning:

  1. You must define the connection to the database:
// with url
Database database = new Datebase( "database", "url connection" );

// ________________________________________________________________

Database.Auth auth = new Database.Auth();
auth.database = "";
auth.host = "";
auth.password = "";
auth.port = 0;
auth.user = "";

// with Auth instance.
Database database = new Datebase( auth );
  1. Methods:
database.close();
// close your database connection.

database.setDefault();
// Used to define this database as default.
// The first instantiation is already defined as default.

💤 Legacy references:

Database#getMongoClient() // MongoClient
Database#getMongoDatabase() // MongoDatabase
Manager#getMongoCollection() // MongoCollection<Document>

⚡ Collection Manager:

Manager<Class> man = new Manager<>( Class );

Manager<Class> man = new Manager<>( Class, Database );

Manager<Class> man = new Manager<>( Class, String );

Manager<Class> man = new Manager<>( Class, String, Database );

// Class: the Element / Structure class.
// "name": optional, the name of the collection (or of the class).
// Database: optional, choose the database!;

🔨 Features:

  • Clear/Drop a collection:
man.drop();
  • Check if document exist by id:
booelan state = man.existObject( "name" );
  • Remove a document by id staticly:
man.remove( "name" );

🔓 Yours Class-Data instances (represents a document):

The instances each represent a document whether it is fictitious or not.
it is thanks to an instance that we can handle a document in the DB (create, modify, delete)

Example blank class-file:

public class **** extends Element {
    public static final Manager<****> manager = new Manager<>(****.class, [["****"]]);
    
    @ID
    protected Object _id;
    
    public **** (final Object id) {
        super(manager);
        this._id = id;
    }
}

Features:

  • Get current document equivalent:
**** instance = ?;

Map<String, Object> doc = instance.serialize(); 
// must catch java.lang.IllegalAccessException
  • Set from document equivalent:
**** instance = ?;

instance.deserialize( map/doc ); 
// must catch java.lang.IllegalAccessException

Extra:

😇 For more help:

  • You can add me on Discord: Matteow#6953

👻 About Me:

  • I am a 17 year old French developer.
  • I started around 12 years old with basic PHP, then around 14 years old I was doing Discord bots in JS with NodeJS.
  • I finally started Java around 15 (so it's been over a year), and my experience has improved over time (see the rest of my Github)