| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -2,6 +2,7 @@ package database | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import ( | 
					 | 
					 | 
					 | 
					import ( | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						"context" | 
					 | 
					 | 
					 | 
						"context" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						"os" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						"go.mongodb.org/mongo-driver/bson/primitive" | 
					 | 
					 | 
					 | 
						"go.mongodb.org/mongo-driver/bson/primitive" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						"go.mongodb.org/mongo-driver/mongo" | 
					 | 
					 | 
					 | 
						"go.mongodb.org/mongo-driver/mongo" | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -11,14 +12,28 @@ import ( | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						"github.com/mainnika/mongox-go-driver/v2/mongox/database" | 
					 | 
					 | 
					 | 
						"github.com/mainnika/mongox-go-driver/v2/mongox/database" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					) | 
					 | 
					 | 
					 | 
					) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					// defaultURI is a mongodb uri that is being used by tests
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					var defaultURI = "mongodb://localhost" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// EphemeralDatabase is a temporary database connection that will be destroyed after close
 | 
					 | 
					 | 
					 | 
					// EphemeralDatabase is a temporary database connection that will be destroyed after close
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					type EphemeralDatabase struct { | 
					 | 
					 | 
					 | 
					type EphemeralDatabase struct { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						mongox.Database | 
					 | 
					 | 
					 | 
						mongox.Database | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					func init() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						envURI := os.Getenv("MONGODB_URI") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						if envURI != "" { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							defaultURI = envURI | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// NewEphemeral creates new mongo connection
 | 
					 | 
					 | 
					 | 
					// NewEphemeral creates new mongo connection
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					func NewEphemeral(URI string) (db *EphemeralDatabase, err error) { | 
					 | 
					 | 
					 | 
					func NewEphemeral(URI string) (db *EphemeralDatabase, err error) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						if URI == "" { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							URI = defaultURI | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						name := primitive.NewObjectID().Hex() | 
					 | 
					 | 
					 | 
						name := primitive.NewObjectID().Hex() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						opts := options.Client().ApplyURI(URI) | 
					 | 
					 | 
					 | 
						opts := options.Client().ApplyURI(URI) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						client, err := mongo.Connect(context.Background(), opts) | 
					 | 
					 | 
					 | 
						client, err := mongo.Connect(context.Background(), opts) | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |