File tree 2 files changed +15
-4
lines changed
2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -83,9 +83,12 @@ Cast strings to number when sorting.
83
83
* [ Mongo Docs] ( https://docs.mongodb.org/manual/tutorial/query-documents/#match-a-field-without-specifying-array-index )
84
84
85
85
With MongoDB, you can search a document with a subarray of objects that you want to match when any one of the elements in the array matches.
86
- This tools implements it in SQL using a subquery so it is not be the most efficient.
86
+ This tool implements it in SQL using a subquery, so it will likely not be the efficient on large datasets .
87
87
88
- Example document.
88
+ To enable subfield matching, you can pass a third parameter which is either an array of field names that will be assumed
89
+ to potentially be arrays or ` true ` if you want it to assume any field can be an array.
90
+
91
+ Example document:
89
92
``` js
90
93
{
91
94
" courses" : [{
@@ -95,9 +98,17 @@ Example document.
95
98
}]
96
99
]
97
100
` ` `
98
- Example query to match:
101
+ Example queries to match:
99
102
` ` ` js
100
103
mongoToPostgres (' data' , { ' courses.distance' : ' 5K' }, [' courses' ])
104
+ mongoToPostgres (' data' , { ' courses.distance' : ' 5K' }, true )
105
+ ` ` `
106
+
107
+ This then creates a PostgreSQL query like the following:
108
+ ` ` `
109
+ (data- > ' courses' - >> ' distance' = ' 5K'
110
+ OR EXISTS (SELECT * FROM jsonb_array_elements (data- > ' courses' )
111
+ WHERE jsonb_typeof (data- > ' courses' )= ' array' AND value- >> ' distance' = ' 5K' ))
101
112
` ` `
102
113
103
114
## Supported Features
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " mongo-query-to-postgres-jsonb" ,
3
- "version" : " 0.2.6 " ,
3
+ "version" : " 0.2.7 " ,
4
4
"description" : " Converts MongoDB queries to postgresql queries for jsonb fields." ,
5
5
"main" : " index.js" ,
6
6
"directories" : {
You can’t perform that action at this time.
0 commit comments