@@ -30,20 +30,41 @@ export const MongoDBBlock: BlockConfig<MongoDBResponse | MongoDBIntrospectRespon
3030 ] ,
3131 value : ( ) => 'query' ,
3232 } ,
33+ {
34+ id : 'connectionMode' ,
35+ title : 'Connection Mode' ,
36+ type : 'dropdown' ,
37+ options : [
38+ { label : 'Host & Port' , id : 'host_port' } ,
39+ { label : 'Connection String (Atlas)' , id : 'connection_string' } ,
40+ ] ,
41+ value : ( ) => 'host_port' ,
42+ } ,
43+ {
44+ id : 'connectionString' ,
45+ title : 'Connection String' ,
46+ type : 'short-input' ,
47+ placeholder : 'mongodb+srv://user:password@cluster.mongodb.net/mydb' ,
48+ password : true ,
49+ condition : { field : 'connectionMode' , value : 'connection_string' } ,
50+ required : { field : 'connectionMode' , value : 'connection_string' } ,
51+ } ,
3352 {
3453 id : 'host' ,
3554 title : 'Host' ,
3655 type : 'short-input' ,
3756 placeholder : 'localhost or your.mongodb.host' ,
38- required : true ,
57+ condition : { field : 'connectionMode' , value : 'connection_string' , not : true } ,
58+ required : { field : 'connectionMode' , value : 'connection_string' , not : true } ,
3959 } ,
4060 {
4161 id : 'port' ,
4262 title : 'Port' ,
4363 type : 'short-input' ,
4464 placeholder : '27017' ,
4565 value : ( ) => '27017' ,
46- required : true ,
66+ condition : { field : 'connectionMode' , value : 'connection_string' , not : true } ,
67+ required : { field : 'connectionMode' , value : 'connection_string' , not : true } ,
4768 } ,
4869 {
4970 id : 'database' ,
@@ -57,15 +78,17 @@ export const MongoDBBlock: BlockConfig<MongoDBResponse | MongoDBIntrospectRespon
5778 title : 'Username' ,
5879 type : 'short-input' ,
5980 placeholder : 'mongodb_user' ,
60- required : true ,
81+ condition : { field : 'connectionMode' , value : 'connection_string' , not : true } ,
82+ required : { field : 'connectionMode' , value : 'connection_string' , not : true } ,
6183 } ,
6284 {
6385 id : 'password' ,
6486 title : 'Password' ,
6587 type : 'short-input' ,
6688 password : true ,
6789 placeholder : 'Your database password' ,
68- required : true ,
90+ condition : { field : 'connectionMode' , value : 'connection_string' , not : true } ,
91+ required : { field : 'connectionMode' , value : 'connection_string' , not : true } ,
6992 } ,
7093 {
7194 id : 'authSource' ,
@@ -837,7 +860,7 @@ Return ONLY the MongoDB query filter as valid JSON - no explanations, no markdow
837860 }
838861 } ,
839862 params : ( params ) => {
840- const { operation, documents, ...rest } = params
863+ const { operation, documents, connectionMode , ...rest } = params
841864
842865 let parsedDocuments
843866 if ( documents && typeof documents === 'string' && documents . trim ( ) ) {
@@ -853,7 +876,7 @@ Return ONLY the MongoDB query filter as valid JSON - no explanations, no markdow
853876 parsedDocuments = documents
854877 }
855878
856- const connectionConfig = {
879+ const connectionConfig : Record < string , unknown > = {
857880 host : rest . host ,
858881 port : typeof rest . port === 'string' ? Number . parseInt ( rest . port , 10 ) : rest . port || 27017 ,
859882 database : rest . database ,
@@ -863,6 +886,10 @@ Return ONLY the MongoDB query filter as valid JSON - no explanations, no markdow
863886 ssl : rest . ssl || 'preferred' ,
864887 }
865888
889+ if ( rest . connectionString ) {
890+ connectionConfig . connectionString = rest . connectionString
891+ }
892+
866893 const result : any = { ...connectionConfig }
867894
868895 if ( rest . collection ) result . collection = rest . collection
@@ -900,6 +927,8 @@ Return ONLY the MongoDB query filter as valid JSON - no explanations, no markdow
900927 } ,
901928 inputs : {
902929 operation : { type : 'string' , description : 'Database operation to perform' } ,
930+ connectionMode : { type : 'string' , description : 'Connection mode (host_port or connection_string)' } ,
931+ connectionString : { type : 'string' , description : 'Full MongoDB connection string' } ,
903932 host : { type : 'string' , description : 'MongoDB host' } ,
904933 port : { type : 'string' , description : 'MongoDB port' } ,
905934 database : { type : 'string' , description : 'Database name' } ,
0 commit comments