1 Preface
Mycat currently supports JDBC-connected back-end databases, which theoretically support any database, such as Oracle, DB2, SQL Server, and so on, to emulate it as MySQL, so only standard SQL statements are supported for other databases, while NoSQL support is packaged with NoSQL APIs JDBC-based implementations.
2 MongoDB in Mycat
MYCAT1.3 has implemented support for MongoDB.
2.1 Configuration Support MongoDB
Modify the following content in the configuration schema.xml file under conf:
Configure Datahost
Add a MongoDB connection under the <dataHost></dataHost> node
<datahost name= "Jdbchost" maxcon= "$" mincon= "1" balance= "0" writetype= "0" dbtype= "MongoDB" dbdriver= "jdbc" >
<writehost host= "hostm" url= "mongodb://192.168.0.99/" user= "admin" password= "123456" ></writeHost>
</dataHost>
Configuration table:
In <schema name= "TESTDB" checksqlschema= "false" sqlmaxlimit= ">" Plus table:
<table name= "People" primarykey= "_id" datanode= "Dn4"/>
Configuration Datanode:
Add a node to <dataNode>:
<datanode name= "Dn4" datahost= "Jdbchost" database= "test"/>
Dbdriver must be JDBC
DBTYPE represents a database type and can be Mysql,oracle,mongodb
By configuring this to support other databases,
2.1.1 Supports Oracle's configuration as follows:
<datahost name= "Jdbchost2" maxcon= "$" mincon= "1" balance= "0" writetype= "0" dbtype= "Oracle" dbdriver= "JDBC" >
<writehost host= "hostM2" url= "JDBC:ORACLE:THIN:@192.168.0.99:1521:ORCL" user= "Jifeng" password= "Jifeng" >< /writehost>
</dataHost>
Configuration of Table,datanode with MongoDB
2.2 Support MongoDB Principle
By implementing the standard JDBC interface, the MongoDB API is invoked to implement the operation on MongoDB.
2.2.1 The jar needed
Mongo-java-driver-2.11.4.jar
This is a Java-enabled driver package that is officially provided by MongoDB.
2.2.2 Implementation principle
By implementing the standard JDBC interface, the MongoDB API is invoked to implement the operation on MongoDB:
(1) Parsing SQL statements (Druid SQL parser as SQL parser)
(2) Convert to MongoDB API
(3) Send to MongoDB server implementation
2.3 Supported SQL Syntax 2.3.1 Create table
CREATE table people (name varchar (), age int,sex int,diqu varchar (a), Lev Int);
You can use it without creating a table in MongoDB.
2.3.2 INSERT INTO INSERT statement
Insert into people (Name,age,sex,diqu,lev) VALUES (' CS ', 22,1, ' sz ', 1);
Note that you must have a field name when inserting data, otherwise you will be prompted with an error:
Data inserted under query:
2.3.3 Update Table Updates statement
Update people set age =23 where name= ' MONGO ';
2.3.4 Select Query Statement 2.3.4.1 support * Query
SELECT * from people where name= ' MONGO ';
2.3.4.2 queries that support specifying field names
Select Name,age from people where name= ' MONGO ';
However, the default _id field for MongoDB is displayed, and the next upgrade resolves the issue.
2.3.4.3 Where Condition 2.3.4.3.1 support equals:
Select Name,age from people where name= ' MONGO ';
2.3.4.3.2 support is greater than:
2.3.4.3.3 support is less than:
2.3.4.3.4 support is less than or equal to:
2.3.4.3.5 support is greater than or equal to
2.3.4.3.6 Support does not equal
2.3.4.3.7 Support and
Support and representation range
Supports multiple and
2.3.4.3.8 Support or
Support for multiple or
2.3.4.3.9 support and and or blending conditions
2.3.4.4 sort
Support for ascending and descending order
Multi-field sorting
2.3.4.5 Support Limit
2.3.5 Delete DELETE statement
Delete from people where name= ' zz ';
2.3.6 DROP statement
drop table people;
Delete a table
2.4 Shards
Data from multiple nodes is automatically merged, but currently does not support paging, sorting, etc.
2.5 Upgrade
Future support for aggregation operations.
Mongodb in Mycat Guide