You are reading the article Learn How With Statement Works In Mariadb? updated in November 2023 on the website Tai-facebook.edu.vn. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 Learn How With Statement Works In Mariadb?
Introduction to MariaDB withMariaDB allows to run subquery expressions; most of the time, the query having a temporary table that is only available for a specified duration of a query. With keyword is used for common table expression. With keyword is help full to run the subquery expression in the statement. We will use common table expressions for recursive common expression data structure and non-recursive common expression data structure with clauses. In recursive common expression, we can execute the query as per the sequence defined by the user. In the non-recursive common table expression sequence of the query, it depends on the other terms. We can use two clauses at a time that is with and cycle clause as per the requirement of the user.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax
with recursive table reference [(colm 1 colm 2)] as ( select…….. ) [cycle cycle colm list restrict ] Select….In the above syntax, we use a keyword followed by a table reference name with all column name lists with respective referenced table; after that, we use a select clause to execute the subquery in the statement. The cycle keyword is used to avoid the infinite loops from the statement. MariaDB supports nonstandard grammar.
When we use cycle ………restrict so there is no difference between union all or union distinct that is union all means all rows without cycles and union distinct all rows should be different.
How with statement works in MariaDB?Let’s see how with works in MariaDB as follows.
Basically, with keyword refers to the common table expression and common table expression and clause is used to execute subquery, and there are two types of common table expression as follows.
Recursive CTE
The common table expression allows the query to reference itself. A recursive common table expression will repeatedly execute a subquery in the statement, or we can say it will execute a subset of data until it obtained the correct result. Mainly recursive common table expression helps handle hierarchical or tree data structures.
Non-Recursive CTE
Basically, non-recursive common table expressions execute the local query, in which we can refer to the other places as per user requirement. Nonrecursive CTE means it does not have any sequence; it depends on any other term in the sequence.
Example of MariaDB withLet’s see the different examples with clauses as follows.
First, we need to create three different tables to implement them with the clause; now, we create tables by using the create table statement as follows.
create table math (no_1 int(20), no_2 int(20), no_3 int(20));Explanation
By using the above syntax, we created table name math with different attributes such as no_1, no_2, and no_3, as shown in the above statement. After that, we insert some records into the math by using insert into statements. The final output of the show databases queries we illustrate by using the following snapshot.
Similarly, we created a second table by using the create table statement as follows.
create table math1 (no_a int(20), no_b int(20), no_c int(20));By using the above syntax, we created table name math1 with different attributes such as no_a, no_b, and no_c, as shown in the above statement. After that, we insert some records into math1 by using insert into statement. The final output of the show databases queries we illustrate by using the following snapshot.
Now create one more table by using the same process as follows.
create table m (no_1 int(20), no_2 int(20), no_3 int(20));Explanation
By using the above syntax, we created table name m with different attributes, as shown in the above statement. After that, we insert some records into them by using insert into statement. The final output of the show databases queries we illustrate by using the following snapshot.
Now we have three different tables now used with clauses to execute subquery as follows.
select math.no_1, math.no_2 from math, math1 select math1.no_c from math1, m where math1.no_c = m.no_1 );Explanation
Now let’s see a recursive example as follows.
We have a table name as BR, and it has different attributes such as origin and end and this we created by using a create table statement.
WITH RECURSIVE bus_dst as ( SELECT origin as end FROM BR WHERE origin='New York' UNION SELECT chúng tôi FROM BR, bus_dst WHERE bus_dst.end= BR.origin ) SELECT * FROM bus_dst;Explanation
In the above example, we use clause and recursive keyword to execute the subquery as shown above. In this example, there are two subqueries see in the above statement, and we need to execute recursively. First is calculated generated result by query then it starts from Mumbai now it added origin cities. The next part of this example is that recursive it selects some cities from the first subquery union with the second subquery; finally, it computes the path for query execution, so in this way, execution of the above statement will be executed. The final output of the show databases queries we illustrate by using the following snapshot.
Similarly, we implement non-recursive common table expressions as per the requirement of the user. We can also use cycle clauses with different options.
ConclusionWe hope from this article you have understood about MariaDB. From this article, we have learned the basic syntax of MariaDB with, as well as common table expressions, and we also see different examples MariaDB with. From this article, we learned how and when we use MariaDB with.
Recommended ArticlesWe hope that this EDUCBA information on “MariaDB with” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
You're reading Learn How With Statement Works In Mariadb?
How Update Statement Works In Pl/Sql?
Definition of PL/SQL UPDATE Statement
PL/SQL provides the update functionality to the users; the update command is used to modify the content of columns in an existing table. The update command uses the SET clause to specify the column name for modification and assign a new value for that field when we use the default, so, at that time, we need to use the default keyword. The update command also uses a where clause to specify conditions for the update. Basically, there are two ways to perform the update command that is traditional, and another is we can perform an update command on one table with records from another table.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax:
update specific table name set colm name 1 = new assigned value, colm name 2 = new assigned value,........... colm name N = new assigned value where [Expression.......] ;Explanation
In the above syntax, we use the update command with different parameters as follows.
specified table name: specified table name means an actual name that we need to modify the data.
colm name: It is a column name from the specified table with a new value that we need to update, so in this way, we can write multiple column names as per requirement.
set: It is the keyword used to set new values to specific columns.
where: where clause to specify the condition for the update command
Let’s see the second syntax as follows.
update specific table name set colm name 1 = (select required expression from specified table name 2 where expression) where[expression];Explanation
This is the second syntax for the update command; this syntax is useful when we need to update records from another table. In the above syntax, we use an update command with different parameters as follows.
colm name: It is the actual column name that we need to update.
After that, we use a subquery, in which we specify the column name with specified table name 2 with where condition as shown.
How does the update statement work in PL/SQL?Now let’s see how the update statement works in Pl/SQL as follows.
In a second way, we need one more table with different records; then, we need to perform the update command with a sub-query. In this method, we can update records from another table with where clause, the where clause basically used to specify which row of the table we need to update.
ExamplesNow let’s see the different examples of update commands in PL/SQL as follows. First, we need to create a new table by using the create table command as follows.
create table studentA(stud_id number(10) not null, stud_name varchar2(30) not null, stud_city varchar2(30));Explanation
By using create table statement, we created a new table name, studentA, with different attributes and different data types. The final output of the above statement we illustrated by using the below screenshot is as follows.
Now insert some records by using insert into the statement as follows.
insert into studentA(stud_id, stud_name, stud_city) values(101,'Jenny','Mumbai'); insert into studentA(stud_id, stud_name, stud_city) values(102,'Johan','Mumbai'); insert into studentA(stud_id, stud_name, stud_city) values(103,'Pooja','London'); insert into studentA(stud_id, stud_name, stud_city) values(104,'Sameer','London'); insert into studentA(stud_id, stud_name, stud_city) values(105,'Rohit', 'London'); select * from studentA;Explanation
Suppose we need to update the student city of Jenny at that time; we can use the following statement as follows.
update studentA set stud_city='Pune' where stud_id=101;Explanation
In the above example, we use the update command; here, we need to update the city of Jenny Pune instead of Mumbai by using stud_id. One more thing is that here we update only a single column. The final output of the above statement we illustrated by using the below screenshot is as follows.
Now let’s see how we can update multiple columns as follows.
update studentA set stud_city='Hongkong', stud_name='Virat' where stud_id=102;Explanation
By using the above statement, we updated two columns because, in my table, there are two columns, but in your case, we updated more than two columns. Here stude_id 102 is duplicated, so that is the reason it updated the row. The final output of the above statement we illustrated by using the below screenshot is as follows.
create table deptB(dept_id number(10) not null, dept_name varchar2(30), stud_id number(10) not null);Explanation
By using the above statement, we created a new table that deptB as shown, and we insert some records into the deptB. The final output of the above statement we illustrated by using the below screenshot is as follows.
Now perform the update command as follows.
update studentA set stud_name = (select dept_name from deptB where deptB.stud_id = studentA.stud_id) where exists (select dept_name from deptB where deptB.stud_id = studentA.stud_id);Explanation
In the above example, we updated records from another table, where we need to update studentA table from the deptB table, so that is why we need to build some relation between these two tables. That means we need a common column in both tables then, and then we can perform the update. The final output of the above statement we illustrated by using the below screenshot is as follows.
See in the above screenshot we updated stud_name from deptB table, here we updated depart name instead of stud_name for understanding purpose, in this way we can update any column name as per our requirement.
ConclusionWe hope from this article you learn PL/SQL update. From the above article, we have learned the basic syntax of updates, and we also see different examples of updates. From this article, we learned how and when we use PL/SQL updates.
Recommended ArticlesWe hope that this EDUCBA information on “PL/SQL UPDATE” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
Learn How It Works With Javafx With Examples?
Introduction to JavaFX FXML
JavaFX FXML is defined as a GUI format with XML-based language launched by Oracle Corporation that enables to compose of the GUIs’ layout or the application of GUIs. The Primary purpose of FXML is to define a user interface. Placing XML mark-up here is to describe a component of UI in the hierarchy structure. A controller takes managing interactions by defining components and link them with them. FXML file has an extension .fxml and it is loaded by FXML Loader by JavaFX,
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
JavaFX FXML is created as below
How does JavaFX FXML work?JavaFX is used to create the Desktop Application, which allows to code the User-interface by making the application easier. In FXML XML elements are a class, script, property, static. A typical JavaFX FXML works like below:
FXML document has a user interface of an FXML application.
FXML Controller handles all the event handling process.
Next, FXML Loader parses the given FXML document and creates a graph. Simultaneously the Main Class initiates the execution of a Program.
For example, when a user accessing a website, he/she checks with the updated information of their needs; therefore, we need to recompile a code. In such a case FXML controller plays a role.
In this article, I have used NetBeans IDE, which supports JavaFX. This IDE typically provides a visual Layout for designing a UI. Deploying the first JavaFx application is needed. To take up the process:
Java file: This takes up a java code for an application (Main Application)
.fxml file: Here FXML source file is created to define a user interface part.
Below is the NetBeans IDE screenshots that support JavaFX. Here we could see three application files in the name JAVAFXApplication1
The following image shows the application that executes with the button event handlers. FXML specifies two event handlers, namely script and Controller event handlers. FXML Layout file could be created for more parts; this keeps the controller and views independently. And the scene Builder doesn’t need XML directly to work with. The stage is the main container, and the Scene is the UI elements here.
Adding Scripts
mainButton.setText(“press me!”); }
Vbox here is a component that makes a form in a vertical order (child elements). We can insert text, labels, and buttons to create a form Layout. Namespaces are added to the root element.
FXML containing stackPane
Using Border Panel
<HBox prefHeight="110.0" prefWidth="210.0"Adding Component inside FXML file
public class load extends VBox implements Initializable { @FXML private void handleAction(ActionEvent eve) { } @Override public void initialize(URL u, ResourceBundle re) { } }FXML annotation is given as
public class layout @FXML private TextField txt; @FXML private Button btn; @FXML private VBox dataContainer; @FXML private TableView tab; ExamplesIn this section, we will show you how to use chúng tôi in Net Beans IDE.
The respective Java class is given as
FXMLsample.java
package fxmlsample; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class FXMLsample extends Application { @Override public void start(Stage st) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("FXMLdoc.fxml")); Scene sc = new Scene(root, 200, 215); st.setTitle("FXML Welcome"); st.setScene(sc); st.show(); } public static void main(String[] args) { launch(args); } }FXMLdoc.fxml
<Text text="Welcome Page" GridPane.columnIndex="0" GridPane.rowIndex="0" <GridPane fx:controller="FXMLdoc.FXML_ctrl"
Next is the controller class with the response to the FXML file for the UI application
FXML_ctrl.java
package FXMLsample; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.text.Text; import javafx.scene.control.Label; public class FXML_ctrl { @FXML private Text actiontarget; @FXML protected void handleSubmitButtonAction(ActionEvent event) { actiontarget.setText("Submit the button"); } }Explanation
The above code section shows to run an FXML application by loading a loader. Similarly, we could see how the components get to each other.
Output:
Features
They have a large set of built-in GUI components like checkboxes; buttons also come with a built-in charts library to create charts.
JavaFX FXML is an XML mark-up language and has a rich set of APIs. It’s a powerful tool and keeps the code easier. Used to develop rich Internet applications using java Files.
JavaFX has CSS styling and gives a declarative layout through FXML.
FXML uses namespaces with the prefix ‘fx’ in which all elements and attributes are assigned. Also, well simple to debug and modify.
ConclusionThis is all about JavaFX FXML. In this article, we had discussed their definition and how it works with JavaFX, along with the examples. Generally, the basics of JavaFX demonstration would not work wells. To build a larger application, we need a system FXML. Therefore, we have explained how it could be used in the development of JavaFX implementation.
Recommended ArticlesThis is a guide to JavaFX FXML. Here we discuss the definition and how it works with JavaFX, along with the examples and features. You may also have a look at the following articles to learn more –
How Does Unless Statement Works In Perl? (Examples)
Definition of Perl unless
Web development, programming languages, Software testing & others
Syntax and ParameterBelow is the syntax of unless statement in perl are as follows.
Syntax #1:
Unless (Boolean expression (condition)) { Statements -- Statement is executed in unless statement when given condition is false. }Syntax #2:
Unless (expression) Block -- Used with unless statement.Syntax #3:
Unless (Condition) Block elsif (condition) Block … else BlockParameter:
Below is the parameter description syntax unless the statement is as follows.
Unless: Unless statement is opposite to if statement in perl, if statement executes the code when statement condition is true it’s reverse in unless statement it will execute the statement when the condition is false. Unless the statement is very useful and important.
Condition: Condition is defined as code in which we have to define condition block if the condition is true then unless the statement will execute the statement under unless statement.
Statement: Statement is defined as a statement that was under unless a statement block. If the condition is true then unless the statement will execute the block of unless statement.
Block: Block is a very important parameter in unless statement. Block is nothing but statement under the condition of unless statement.
Expression: Expression is defined as the condition of code unless statement.
FlowchartBelow is the flowchart of unless statement is as follows. A flowchart is nothing but a step by step execution of the program code. The below figure shows flowchart of unless statement.
Flowchart is very important to find the step by step execution of unless statement that how it works in program statements.
The above figure shows the pictorial representation or flow of unless statement in program code. How unless is working, it shows in the flowchart.
Flowchart of unless the statement starts with keyword name as start and end with the name as stop or we can also end the flowchart with name as end keyword.
After the starting off the flowchart compiler will check the condition or block of code if the condition is false then it will execute the statement under the conditional block of unless statement.
If the condition is false then the compiler will execute the statement or block of code. If the condition is true then unless the statement will skip the block of code from program statement.
Flowchart is very important to display the pictorial flow of any program or code in perl language.
How does unless Statement Works in Perl?Below is the working of unless statement is as follows.
Unless statement is opposite to if statement, in if statement execute the code when statement condition is true it’s reverse in unless statement it will execute the statement when the condition is false.
We can use unless a statement with else to define multiple conditions in a single program.
Perl unless the statement is opposite to if statement. It will execute the multiple statements inside the body unless a statement when the given statement condition is false.
It is very useful and important to execute multiple statements at one time when a given condition is false. We can use else if statement with unless statement.
We can use unless statement followed by else statement. The unless statement will execute the statement from right to left when the given condition is false.
Perl will execute the statement which was precedes by unless. If the condition statement is true then perl will skip the statement of block code.
We have used the following form of a statement unless statement when we have to execute more than one statement.
Unless (condition) { }
If the condition of the above code is false then it will execute the block of code. If the condition of the above code is true then it will skip the block of code.
Examples of Perl unlessBelow is the example of unless statement is as follows.
1. Unless in Perl Using False ConditionThe below example shows that unless in perl using a false condition. We have used a false condition block in the below example.
Example:
$n = 30; # Check the condition using unless in perl if the condition is false execute the block of statement. unless( $n < 25 ) { # If condition of statement is false then execute below statement. printf "Condition falsen"; } print "value of n is : $nn"; $n = ""; # check the boolean condition. unless ( $n ) { # If condition of statement is false then execute below statement. printf "n has n false valuen"; } print "value of n is : $nn";' 2. Unless in Perl Using True ConditionThe below example shows that unless using a true condition. We have used a true condition block in the below example.
Example:
$n = 10; # Check the condition using unless in perl if the condition is false execute the block of statement. unless( $n < 25 ) { # If condition of statement is false then execute below statement. printf "Condition truen"; } print "value of n is : $nn"; $n = ""; # check the boolean condition. unless ( $n ) { # If condition of statement is false then execute below statement. printf "n has n false valuen"; } print "value of n is : $nn";Output:
Recommended ArticlesThis is a guide to Perl unless. Here we also discuss the definition and how does unless statement works in perl along with different examples and its code implementation. You may also have a look at the following articles to learn more –
How Include Works In Linq With Examples?
Introduction to LINQ Include
Web development, programming languages, Software testing & others
Syntax:
Let’s understand the following syntax,
var C_OrderDetails=context.customer details.Include ("OrderDetails").ToList();In this syntax, we use the include method to combine the related entities in the same query, like merging multiple entities in a single query.
How does include work in LINQ? Var COrderDetails=context.CustomerDetails.Include ("OrderDetails").ToList();By using only SQL statements instead of using the Include() methods, we need to generate the following queries to retrieve the same above,
SELECT * FROM CustomerDetails;Instead of using Include (“OrderDetails”), the code looks as follows,
SELECT * FROM CustomerDetails JOIN OrderDetails ON Customer_ID=OrderDetails.Customer_ID; Var Customer_OrderDetails= context.CustomerDetails.Include("OrderDetails").Include("LineItems").Include ("ProducDetails").ToList();We can make it use multiple calls to Include() to get the objects along various paths. If you require the objects in the same path, you must make a single call specifying the entire path.
ExampleWhen using Include, if we have n number of queries to execute n number of times that is time-consuming, then it’s like select N+1 problem; this issue happens only because the lazy loading mechanism enables by default to execute a single query n number of queries to do something. So it’s better to avoid the select N+1 problem in Entity Framework; we need to use the Include Method, which helps to build a single query with required data using the Join clause, and this is the most resourceful way compared to executing queries multiple times.
Let’s see the sample program with the use of LINQ_Include. We need to include the namespace chúng tôi entity which the LINQ Include is an extension method of the Data.Entity namespace. Entity Framework version provides LINQ Include() by using chúng tôi and System.Data.Entity.
Code:
using System; using System.Data.Entity; using System.Linq; using System.Collections.Generic; public class Program_LINQ_Include { public static void Main() { Inserting_Data(); using (var context = new EntityContext()) { var customers = context.Customers .ToList(); Displaying_Data(customers); } } public static void Inserting_Data() { using (var context = new EntityContext()) { context.BulkInsert(CustomerData()); context.BulkInsert(InvoiceData()); context.BulkInsert(ItemData()); } } { { new Customer() { Name ="Peter"}, new Customer() { Name ="Smith"}, new Customer() { Name ="James"} }; return list; } { { new Invoice() { Date = new DateTime(2023,5,3), CustomerID = 1}, new Invoice() { Date = DateTime.Now.AddDays(-5), CustomerID = 1}, new Invoice() { Date = DateTime.Now.AddDays(-3), CustomerID = 1}, new Invoice() { Date = new DateTime(2023,4,15), CustomerID = 2}, new Invoice() { Date = new DateTime(2023,2,20), CustomerID = 3}, new Invoice() { Date = new DateTime(2023,5,22), CustomerID = 3}, }; return list; } { { new Item() { Name = "Mobile-Charger", InvoiceID = 1}, new Item() { Name = "Laptop-DELL", InvoiceID = 1}, new Item() { Name = "Stationeries", InvoiceID = 1}, new Item() { Name = "Note-Books", InvoiceID = 2}, new Item() { Name = "DataCard", InvoiceID = 2}, new Item() { Name = "PenDrive", InvoiceID = 3}, new Item() { Name = "Water-Bottles", InvoiceID = 3}, new Item() { Name = "Stationeries", InvoiceID = 3}, new Item() { Name = "DataCard", InvoiceID = 4}, new Item() { Name = "School-Bags", InvoiceID = 4}, new Item() { Name = "Table-Chairs", InvoiceID = 4}, new Item() { Name = "Lap-Table", InvoiceID = 4}, new Item() { Name = "Mobile-Charger", InvoiceID = 5}, new Item() { Name = "School-Bags", InvoiceID = 5}, new Item() { Name = "Stationeries", InvoiceID = 6}, new Item() { Name = "Laptop-DELL", InvoiceID = 6}, new Item() { Name = "Loptop-Cover", InvoiceID = 6}, new Item() { Name = "PenDrive", InvoiceID = 6}, new Item() { Name = "Memory-Card", InvoiceID = 6}, new Item() { Name = "Mobile-Charger", InvoiceID = 6}, new Item() { Name = "School-Bags", InvoiceID = 6}, new Item() { Name = "Touch-Pad", InvoiceID = 6}, }; return list; } { foreach(var customer in list) { Console.WriteLine(customer.Name); foreach(var invoice in customer.Invoices) { Console.WriteLine("t" + invoice.Date); foreach(var item in invoice.Items) { Console.WriteLine("tt" + item.Name); } } } Console.WriteLine("tt"); } }Output:
Let’s understand the above example, like how the LINQ Includes functionality to load the related entities. To assume that the Customer_Details Object has links to its Invoice_Details and those orders have an ItemData reference. Likewise, we can make several links to the related objects by using LINQ Include(), which allows you to specify the related entities to be read from the database in a single query.
ConclusionI have explained the LINQ Include() method with several examples programmatically in this article. It enables us to retrieve the related entities from the database in the same query. Using the Include method in a single query, we can easily read all related entities from the database.
Recommended ArticlesThis is a guide to LINQ Include. Here we discuss the Introduction, Syntax, and working of include method, example, and code implementation. You may also have a look at the following articles to learn more –
How Json Works In Mongodb With Examples
Introduction to MongoDB JSON
MongoDB JSON is the lightweight interchange format; we can easily transfer MongoDB JSON from one system to other. Also, we can easily read and write the file; the abbreviated name of MongoDB JSON is JavaScript object notation. In MongoDB, high-level JSON has two entities. First is an object, and the second is an array; the object is nothing but the value pair collection, and the array is a list of order values; using these two entities, we can develop complete documents in MongoDB. While creating a JSON object is started with braces and then comes key and value.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
Syntax of MongoDB JSON
Given below is the syntax mentioned:
1. MongoDB JSON document structure syntax.
}
In the above syntax, field1 to fieldN contains the field which was we have used in the JSON documents.
Value1 to ValueN is the value of the JSON field.
Mongoexport –collection = collection_name –db = db_name –out = filename.JSON
In the above syntax, we are creating the dump file.
The parameter mongoexport is used to export the collection into the JSON file.
Collection parameter is used to export the specified collection into the file.
DB parameter is used to export the specified database collection into the file.
Out parameter is the default that we need to use when exporting any collection in MongoDB.
The filename is the name of the JSON dump file.
3. Import the MongoDB JSON file.
In the above syntax, we are importing the JSON dump file into the specified collection.
The parameter mongoimport is used for import the JSON file data.
The collection parameter is used to import the data into the specified collection from the file.
DB parameter is used to import the data into a specified database collected from the file.
How JSON Works in MongoDB?It is the plain text which was written in JavaScript object notation. We can use it to send the data between one computer to another computer. The use of JSON in MongoDB is very easy; also, we can use the JavaScript built-in function to convert the JSON strings into the object of JavaScript’s.
There is two built-in functions:
JSON.parse ()
JSON. Stringify ()
It supports all the data types.
Below data type is supported by MongoDB JSON:
Number
Array
Boolean
String
It makes the notation of key-value pair using strings, and it will easily be exported and imported into the various tools. The important function of JSON is to transmit the data between web applications and servers. It is basically used the alternate of an XML, which is the language-independent data format. It has a UTF-8 string format. Thus, humans and machines both understand and read the data of files.
It provides a flexible database and schema design as compared to the tabular data model, which was used in relational database models. Basically, documents are polymorphic; the fields can vary from one document to another within the same collection. Using it, we have no need to create the structure of documents for the database. We can directly start our development without creating any structure.
Examples of MongoDB JSONDifferent examples are mentioned below:
Example #1Insert the data using string data types.
In the below example, we have inserted the string value name as ABC into the MongoDB_JSON collection. Thus, the name attribute shows the field, and the ABC string shows the value of the field.
Code:
db.MongoDB_JSON.find ().pretty ()
Output:
Example #2Insert the data using numeric data types.
In the below example, we have inserted the numeric value emp_id as 101 into the MongoDB_JSON collection. Thus, the Emp_id attribute shows the field, and 101 integers are shown the value of a field.
Code:
Output:
Example #3Insert the data using array data types.
In the below example, we have inserted the array value into the MongoDB_JSON collection. Therefore, we have to assign MongoDB_JSON the same name as the field and the value.
Code:
var MongoDB_JSON = ["MongoDB is NoSQL DB", "MySQL is OpenSource DB", "PostgreSQL is object RDBMS"] db.MongoDB_JSON.find ().pretty ()
Output:
Example #4Insert the data using Boolean data types.
In the below example, we have inserted the Boolean value name as true and the middlename as false into the MongoDB_JSON collection. Name and middlename attribute shows the field, and true, false Boolean value shows the value of the field.
Code:
> db.MongoDB_JSON.find ().pretty ()
Output:
Example #5Below example shows export MongoDB_JSON collection into the MongoDB_JSON. Json file.
After exporting the data into the JSON file, we can see this file using the cat command. This data comes in a human-readable format.
Code:
[[email protected] ~]# cat MongoDB_JSON. Json
Output:
Example #6MongoDB import from the JSON file.
The below example shows that import the data into the Mongo_JSON_NEW collection from the MongoDB_JSON. Json file.
Code:
db.Mongo_JSON_NEW.find().pretty()
Output:
ConclusionThey have their multiple data types are available in MongoDB; using this datatype, we can insert the data into the collection. We can import the data into the collection from JSON file using mongoimport; we can also export the collected data into the JSON file using mongoexport.
Recommended ArticlesThis is a guide to MongoDB JSON. Here we discuss the introduction, how JSON works in MongoDB? and examples for better understanding. You may also have a look at the following articles to learn more –
Update the detailed information about Learn How With Statement Works In Mariadb? on the Tai-facebook.edu.vn website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!