Query Builder
The Query Builder allows users to create complex queries for MongoDB without writing code. It provides an intuitive interface where you can build, modify, and preview queries directly within the application. This tool is especially useful for users who prefer a graphical interface over traditional query scripting.
Key Features
- Schema Exploration: Visualize and explore the schema of the entities and their records.
- Drag-and-Drop Query Building: Create queries by dragging fields from the schema into the query builder.
- Real-Time Preview: See the results of your query as you build it.
- Logical Grouping: Combine multiple rules and groups to create advanced queries.
- Rule Customization: Define custom conditions for each field.
- Two-Way Sync: Modify the query in the builder or the raw code editor, and see the changes reflected in real-time.
Accessing the Query Builder
- Navigate to the Data section in the sidebar.
- Select Entity from the list of entities.
- Click on the "Query" button
Interface Overview
The Visual Query Builder interface is divided into several key sections:
1.Example and Schema (Top Left Panel)
Example: Shows a sample document from the entity.
- You can drag-and-drop fields from the example tab to the Filter builder tab. Rulle will be populated with the field name and value.
- Search bar allows you to search for fields in the example tab.
- Arrow buttons allow you to navigate between different example documents.
Schema: Displays the schema of the entity.
- You can drag-and-drop fields from the schema tab to the Filter builder tab. Rule will be populated with the field name.
Main difference between Example and Schema tabs is that Example tab shows the actual record from the entity, while Schema tab shows the schema of the entity.
2.Filter Builder (Right Panel)
- Drag-and-Drop Interface: Drag fields from the Example or Schema tab to create rules.
- Logical Operators: Combine rules using AND, OR, and NOT operators.
- Rule Customization: Define custom conditions for each field.
- Grouping: Create groups of rules to build complex queries.
3.Result Preview (Bottom Panel)
- Displays the results of the query in real-time
4.Raw Query Editor (Right Panel)
- Allows advanced users to directly edit the Mongo-like query syntax if they prefer.
Building a Query
Simple Query
- Drag a field from the Example or Schema tab to the Filter Builder.
- Define the condition for the field.
- You can see the results in the Result Preview panel.
- You can add more fields and conditions to the query. Rules without any logical operators are combined using the AND operator.
- Click on "Save and close" to save the query.
Complex Query
- Add group to the query by clicking on the "Add Group" button.
- Select the logical operator for the group.
- Drag fields to the group and define conditions.
- You can nest groups within groups to create complex queries.
- Click on "Save and close" to save the query.
Types and Conditions
The Query Builder supports various field types and conditions for building queries.
Any Types
- "Type" - Matches values based on their BSON type.
- "Empty" - Matches fields that are empty or null.
- "Not Empty" - Matches fields that are not empty or null.
- "Exists" - Matches fields that exist in the document.
- "Not Exists" - Matches fields that do not exist in the document.
Number and Date
- "=" (Equal) - Matches values that are equal to the specified value.
- "!=" (Not Equal) - Matches values that are not equal to the specified value.
- ">" (Greater Than) - Matches values that are greater than the specified value.
- "<" (Less Than) - Matches values that are less than the specified value.
- ">=" (Greater Than or Equal) - Matches values that are greater than or equal to the specified value.
- "<=" (Less Than or Equal) - Matches values that are less than or equal to the specified value.
- "<= ... <=" This condition checks if a value falls within a range that includes both endpoints. For example, if you set the condition as 10 <= field <= 20, it will match all values from 10 to 20, including both 10 and 20.
- "< ... <=" : This condition checks if a value falls within a range that excludes the lower endpoint but includes the upper endpoint.
- "<= ... <" : This condition checks if a value falls within a range that includes the lower endpoint but excludes the upper endpoint.
- "< ... <" : This condition checks if a value falls within a range that excludes both endpoints.
- "in" (In) - Matches any of the values specified in an array. You can add values by clicking on the "+" button. \ You can select type of value in array.
String
- "=" (Equal) - Matches values that are equal to the specified value.
- "!=" (Not Equal) - Matches values that are not equal to the specified value.
- "in" (In) - Matches any of the values specified in an array. You can add values by clicking on the "+" button.
- "contains" (Contains) - Matches values that contain the specified substring.
- "Starts with" (Starts With) - Matches values that start with the specified substring.
- "Ends with" (Ends With) - Matches values that end with the specified substring.
Boolean
- "=" (Equal) - Matches values that are equal to the specified value.
- "!=" (Not Equal) - Matches values that are not equal to the specified value.
Array
- "=" - Return documents where the array field contains value
- "=[]" - Return documents where the array field is equal to the specified array regard to order
- "All" - Return documents where the array field contains all the specified values regadless of order
- "In" - Return documents where the array field contains any of the specified values
- "Size" - Return documents where the array field has the specified size
- "Element Match" - Return documents where the array field contains at least one element that matches the specified condition If you array contains objects, you can specify conditions for each field of object.