Protocol modules in MariaDB MaxScale interpret client-server communication. This section covers the available protocols, including the MariaDB, NoSQL, and Change Data Capture (CDC) modules.
[CDC-Service]
type=service
router=avrorouter
user=maxuser
password=maxpwdfoobar:SHA1(foopasswd) -> 666f6f6261723a3137336363643535253331REGISTER UUID=11ec2300-2e23-11e6-8308-0002a5d5c51b, TYPE=AVROREQUEST-DATA db1.table1
REQUEST-DATA dbi1.table1.000003
REQUEST-DATA db2.table4 0-11-345[avro-service]
type=service
router=avrorouter
source=replication-service
user=cdc_user
password=cdc_passwordmaxctrl call command cdc add_user <service> <name> <password>bash$ cdc_users.py [-h] USER PASSWORDbash$ cdc_users.py user1 pass1 >> /var/lib/maxscale/avro-service/cdcusers[TheService]
type=service
...
[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
nosqlprotocol.user=the_user
nosqlprotocol.password=the_password
port=17017root35INSERTordereddefaultmaxctrl create listener TheService MongoDB-Listener --protocol=nosqlprotocol 'nosqlprotocol={"user":"the_user", "password": "the_password"}'const uri = "mongodb://127.0.0.1:17017"$ mongo --host 127.0.0.1 --port 17017
MongoDB shell version v4.4.1
...
>MariaDB [(none)]> select user, host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| bob | % |
| mysql | localhost |
+-------------+-----------+
2 rows in set (0.001 sec)> use test;
switched to db test
> db.runCommand({createUser: "bob", pwd: "bobspwd", roles: []});
{ "ok" : 1 }MariaDB [(none)]> select user, host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| bob | % |
| test.bob | % |
| mysql | localhost |
+-------------+-----------+
3 rows in set (0.001 sec)> use mariadb
switched to db mariadb
> db.runCommand({createUser: "bob", pwd: "bobspwd", roles: []});
{
"ok" : 0,
"errmsg" : "User \"bob\" already exists",
"code" : 51003,
"codeName" : "Location51003"
}> db.runCommand({createUser: "alice", pwd: "alicespwd", roles: []});
{ "ok" : 1 }MariaDB [(none)]> select user, host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| alice | % |
| bob | % |
| test.bob | % |
| mysql | localhost |
+-------------+-----------+
4 rows in set (0.001 sec)...
nosqlprotocol.user=theuser
nosqlprotocol.password=thepasswordnosqlprotocol.authentication_required=truenosqlprotocol.authorization_enabled=truenosqlprotocol.user = user_with_privileges_for_creating_a_user
nosqlprotocol.password = the_users_password$ mongo --port 17017
...
>> use admin;
switched to db admin
> db.runCommand({createUser: "nosql_admin", pwd: "nosql_pwd", roles: ["userAdmin"]});
{ "ok" : 1 }> use mariadb;
switched to db admin
> db.runCommand({mxsAddUser: "bob", pwd: "bob_pwd", roles: ["userAdmin"]});
{ "ok" : 1 }nosqlprotocol.authentication_required=true
nosqlprotocol.authorization_enabled=true> use test;
switched to db test
> db.runCommand({createUser: "alice", pwd: "alices_pwd", roles: []});
{
"ok" : 0,
"errmsg" : "command createUser requires authentication",
"code" : 13,
"codeName" : "Unauthorized"
}[NoSQL-Listener]
...
nosqlprotocol.user=db.the_user
nosqlprotocol.password=the_password
nosqlprotocol.authentication_required=true
nosqlprotocol.authorization_enabled=true
...CREATE USER 'admin.nosql_admin'@'%' IDENTIFIED BY 'nosql_password';
GRANT ALL PRIVILEGES ON *.* TO 'admin.nosql_admin'@'%' WITH GRANT OPTION;[NoSQL-Listener]
type=listener
service=...
protocol=nosqlprotocol
nosqlprotocol.user=admin.nosql_admin
nosqlprotocol.password=nosql_password
nosqlprotocol.authentication_required=true
nosqlprotocol.authorization_enabled=true... notice : [nosqlprotocol] Created initial NoSQL user 'admin.nosql_admin'.$ mongo --quiet --port 17017 -u nosql_admin -p nosql_password admin
>> db.runCommand({usersInfo: 1});
{
"users" : [
{
"_id" : "admin.nosql_admin",
"userId" : UUID("7d921459-3099-42a7-ad06-ed37ac002161"),
"user" : "nosql_admin",
"db" : "admin",
"roles" : [
{
"db" : "admin",
"role" : "dbAdminAnyDatabase"
},
{
"db" : "admin",
"role" : "readWriteAnyDatabase"
},
{
"db" : "admin",
"role" : "userAdminAnyDatabase"
},
{
"db" : "admin",
"role" : "root"
}
],
"mechanisms" : [
"SCRAM-SHA-256"
]
}
],
"ok" : 1
}CREATE USER 'test.test_user'@'%' IDENTIFIED BY 'test_password';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX ON `test`.* TO 'test.test_user'@'%';[NoSQL-Listener]
type=listener
service=...
protocol=nosqlprotocol
nosqlprotocol.user=test.test_user
nosqlprotocol.password=test_password
nosqlprotocol.authentication_required=true
nosqlprotocol.authorization_enabled=true... notice : [nosqlprotocol] Created initial NoSQL user 'test.test_user'.$ mongo --quiet --port 17017 -u test_user -p test_password test
>> db.runCommand({usersInfo: 1});
{
"users" : [
{
"_id" : "test.test_user",
"userId" : UUID("714f35e7-4276-45af-863c-0be4d1f5dd74"),
"user" : "test_user",
"db" : "test",
"roles" : [
{
"db" : "test",
"role" : "readWrite"
}
],
"mechanisms" : [
"SCRAM-SHA-256"
]
}
],
"ok" : 1
}[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
...[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
...[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
nosqlprotocol.user=the_user
nosqlprotocol.password=the_password
nosqlprotocol.on_unknown_command=return_error
...nosqlprotocol.debug=in,out,backCREATE TABLE name (id VARCHAR(35) AS (JSON_COMPACT(JSON_EXTRACT(doc, "$._id"))) UNIQUE KEY,
doc JSON,
CONSTRAINT id_not_null CHECK(id IS NOT NULL));{ <field1>: <value>, <field2>: <value> ... }> db.runCommand({find: "collection", filter: { _id: 4711 }});> db.runCommand({find: "collection", filter: { _id: { $eq: 4711 }}});... WHERE (id = '4711')... WHERE (JSON_EXTRACT(doc, '$._id') = 4711)updates: [
{
q: <query>,
u: { $set: { status: "D" } },
...
},
...
]updates: [
{
q: <query>,
u: { status: "D", quantity: 4 },
...
},
...
]{ ok: 1 }> use myDatabase;
> db.runCommand({createUser: "user1", pwd: "pwd1", roles: []});{
"ok" : 0,
"errmsg" : "not running with --replSet",
"code" : 76,
"codeName" : "NoReplicationEnabled"
}{ "ok" : 1 }{
"errmsg" : "fsync not supported by MaxScale:nosqlprotocol",
"code" : 115,
"codeName" : "CommandNotSupported",
"ok" : 0
}{ "ok" : 1 }{ "state" : "undecided", "ok" : 1 }db.runCommand(
{
mxsAddUser: "<name>",
pwd: passwordPrompt(), // Or "<cleartext password>"
customData: { <any information> },
roles: [
{ role: "<role>", db: "<database>" } | "<role>",
...
],
mechanisms: [ "<scram-mechanism>", ...],
digestPassword: <boolean>
}
)> db.runCommand({mxsAddUser: "user", pwd: "pwd", roles: ["readWrite"]});
{ "ok" : 1 }> db.runCommand({mxsAddUser: "user2", pwd: "pwd2", roles: ["redWrite"]});
{
"ok" : 0,
"errmsg" : "No role named redWrite@test",
"code" : 31,
"codeName" : "RoleNotFound"
}db.adminCommand(
{
mxsCreateDatabase: <name>
}
)> db.adminCommand({mxsCreateDatabase: "db"});
{ "ok" : 1 }> db.adminCommand({mxsCreateDatabase: "db"});
{
"ok" : 0,
"errmsg" : "The database 'db' exists already.",
"code" : 48,
"codeName" : "NamespaceExists"
}db.runCommand(
{
mxsDiagnose: <command>
}
)> db.runCommand({mxsDiagnose: {ping:1}});
{ "kind" : "immediate", "response" : { "ok" : 1 }, "ok" : 1 }
> db.runCommand({mxsDiagnose: {find:"person", filter: { name: "Bob"}}});
{
"kind" : "single",
"sql" : "SELECT doc FROM `test`.`person` WHERE ( JSON_EXTRACT(doc, '$.name') = 'Bob') ",
"ok" : 1
}
> db.runCommand({mxsDiagnose: {delete:"person", deletes: [{q: { name: "Bob"}, limit:0}, {q: {name: "Alice"}, limit:0}]}});
{
"kind" : "single",
"sql" : [
"DELETE FROM `test`.`person` WHERE ( JSON_EXTRACT(doc, '$.name') = 'Bob') ",
"DELETE FROM `test`.`person` WHERE ( JSON_EXTRACT(doc, '$.name') = 'Alice') "
],
"ok" : 1
}db.runCommand(
{
mxsGetConfig: <any>
});> db.runCommand({mxsGetConfig: 1});
{
"config" : {
"on_unknown_command" : "return_error",
"auto_create_tables" : true,
"id_length" : 35
...
},
"ok" : 1
}db.runCommand(
{
mxsListTables: <any>
});> db.runCommand({mxsListTables:"hello"});
{
cursor: {
id: Long('0'),
ns: 'test.$cmd.mxsListTables',
firstBatch: [
{ name: 'Cars', nosql: true },
{ name: 'Customers', nosql: false },
]
},
ok: 1
}db.runCommand(
{
mxsRemoveUser: "<name>"
}
)> db.runCommand({mxsRemoveUser: "user"});
{ "ok" : 1 }> db.runCommand({mxsRemoveUser: "user"});
{
"ok" : 0,
"errmsg" : "User 'user@test' not found",
"code" : 11,
"codeName" : "UserNotFound"
}db.runCommand(
{
mxsSetConfig: document
});> db.runCommand({mxsGetConfig: 1});
{
"config" : {
"on_unknown_command" : "return_error",
"auto_create_tables" : true,
"id_length" : 35
...
},
"ok" : 1
}
> db.runCommand({mxsSetConfig: { auto_create_tables: false}});
{
"config" : {
"on_unknown_command" : "return_error",
"auto_create_tables" : false,
"id_length" : 35
...
},
"ok" : 1
}db.runCommand(
{
mxsUpdateUser: "<name>",
pwd: passwordPrompt(), // Or "<cleartext password>"
customData: { <any information> },
roles: [
{ role: "<role>", db: "<database>" } | "<role>",
...
],
mechanisms: [ "<scram-mechanism>", ...],
digestPassword: <boolean>
}
)> db.runCommand({mxsUpdateUser: "user", pwd: "pwd", roles: ["readWrite"]});
{ "ok" : 1 }> db.runCommand({mxsUpdateUser: "user", roles: ["redWrite"]});
{
"ok" : 0,
"errmsg" : "No role named redWrite@test",
"code" : 31,
"codeName" : "RoleNotFound"
}[My-NoSQL-Listener]
...
nosqlprotocol.internal_cache=cache[My-NoSQL-Listener]
...
nosqlprotocol.internal_cache=cache
nosqlprotocol.cache.max_size=10M
nosqlprotocol.cache.soft_ttl=30s
nosqlprotocol.cache.hard_ttl=40s
...[TheService]
type=service
...
[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
nosqlprotocol.user=the_user
nosqlprotocol.password=the_password
port=17017... notice : (NoSQL-Listener); Listening for connections at [127.0.0.1]:17017$ mongo --port 17017
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:17017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("694f3eed-329f-487a-8d73-9a2d4cf82d62") }
MongoDB server version: 4.4.1
---
...
---
>> db.runCommand({insert: "collection", documents: [{_id: 1, "hello": "world"}]});
{ "n" : 1, "ok" : 1 }> db.runCommand({find: "collection"});
{
"cursor" : {
"firstBatch" : [
{
"_id" : 1,
"hello" : "world"
}
],
"id" : NumberLong(0),
"ns" : "test.collection"
},
"ok" : 1
}MariaDB [(none)]> select * from test.collection;
+------+------------------------------------+
| id | doc |
+------+------------------------------------+
| 1.0 | { "_id" : 1.0, "hello" : "world" } |
+------+------------------------------------+> db.runCommand({mxsDiagnose: {insert: "collection", documents: [{_id: 1, "hello": "world"}]}});
{
"kind" : "multi",
"sql" : [
"INSERT INTO `test`.`collection` (doc) VALUES ('{ \"_id\" : 1.0, \"hello\" : \"world\" }')"
],
"ok" : 1
}> db.runCommand({mxsDiagnose: {find: "collection"}});
{
"kind" : "single",
"sql" : "SELECT doc FROM `test`.`collection` ",
"ok" : 1
}const uri = "mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority";const uri = "mongodb://<maxscale-ip>:17017";const { MongoClient } = require("mongodb");
const uri = "mongodb://127.0.0.1:17017";
const client = new MongoClient(uri, { useUnifiedTopology: true });
async function run() {
try {
await client.connect();
const database = client.db("mydb");
const movies = database.collection("movies");
// create a document to be inserted
const movie = { title: "Apocalypse Now", director: "Francis Ford Coppola" };
const result = await movies.insertOne(movie);
console.log(
`${result.insertedCount} documents were inserted with the _id: ${result.insertedId}`,
);
} finally {
await client.close();
}
}
run().catch(console.dir);$ nodejs insert.js
1 documents were inserted with the _id: 60afca73bf486114e3fb48b8const { MongoClient } = require("mongodb");
const uri = "mongodb://127.0.0.1:17017";
const client = new MongoClient(uri, { useUnifiedTopology: true });
async function run() {
try {
await client.connect();
const database = client.db("mydb");
const movies = database.collection("movies");
// Query for a movie that has the title 'Apocalypse Now'
const query = { title: "Apocalypse Now" };
const options = {
// Include only the 'director' field in the returned document
projection: { _id: 0, director: 1 },
};
const movie = await movies.findOne(query, options);
// Returns a document and not a cursor, so print directly.
console.log(movie);
} finally {
await client.close();
}
}
run().catch(console.dir);$ nodejs find.js
{ director: 'Francis Ford Coppola' }* [Authentication Commands](#authentication-commands)
* [Logout](#logout)
* [User Management Commands](#user-management-commands)
* [createUser](#createuser)
* [dropAllUsersFromDatabase](#dropallusersfromdatabase)
* [dropUser](#dropuser)
* [grantRolesToUser](#grantrolestouser)
* [revokeRolesFromUser](#revokerolesfromuser)
* [updateUser](#updateuser)
* [usersInfo](#usersinfo)
* [Replication Commands](#replication-commands)
* [isMaster](#ismaster)
* [replSetGetStatus](#replsetgetstatus)
* [Sessions Commands](#sessions-commands)
* [endSessions](#endsessions)
* [Administration Commands](#administration-commands)
* [create](#create)
* [createIndexes](#createindexes)
* [drop](#drop)
* [dropDatabase](#dropdatabase)
* [dropIndexes](#dropindexes)
* [fsync](#fsync)
* [killCursors](#killcursors)
* [listCollections](#listcollections)
* [listDatabases](#listdatabases)
* [listIndexes](#listindexes)
* [renameCollection](#renamecollection)
* [setParameter](#setparameter)
* [Diagnostic Commands](#diagnostic-commands)
* [buildInfo](#buildinfo)
* [explain](#explain)
* [getCmdLineOpts](#getcmdlineopts)
* [getLog](#getlog)
* [hostInfo](#hostinfo)
* [listCommands](#listcommands)
* [ping](#ping)
* [serverStatus](#serverstatus)
* [validate](#validate)
* [whatsmyuri](#whatsmyuri)
* [Free Monitoring Commands](#free-monitoring-commands)
* [getFreeMonitoringStatus](#getfreemonitoringstatus)
* [MaxScale Specific Commands](#maxscale-specific-commands)
* [mxsAddUser](#mxsadduser)
* [Definition](#definition)
* [mxsAddUser](#mxsadduser_1)
* [Syntax](#syntax)
* [Command Fields](#command-fields)
* [Returns](#returns)
* [mxsCreateDatabase](#mxscreatedatabase)
* [Definition](#definition_1)
* [mxsCreateDatabase](#mxscreatedatabase_1)
* [Syntax](#syntax_1)
* [Command Fields](#command-fields_1)
* [Returns](#returns_1)
* [mxsDiagnose](#mxsdiagnose)
* [Definition](#definition_2)
* [mxsDiagnose](#mxsdiagnose_1)
* [Syntax](#syntax_2)
* [Command Fields](#command-fields_2)
* [Returns](#returns_2)
* [mxsGetConfig](#mxsgetconfig)
* [Definition](#definition_3)
* [mxsGetConfig](#mxsgetconfig_1)
* [Syntax](#syntax_3)
* [Command Fields](#command-fields_3)
* [Returns](#returns_3)
* [mxsListTables](#mxslisttables)
* [Definition](#definition_4)
* [mxsListTables](#mxslisttables_1)
* [Syntax](#syntax_4)
* [Command Fields](#command-fields_4)
* [Returns](#returns_4)
* [mxsRemoveUser](#mxsremoveuser)
* [Definition](#definition_5)
* [mxsRemoveUser](#mxsremoveuser_1)
* [Syntax](#syntax_5)
* [Command Fields](#command-fields_5)
* [Returns](#returns_5)
* [mxsSetConfig](#mxssetconfig)
* [Definition](#definition_6)
* [mxsSetConfig](#mxssetconfig_1)
* [Syntax](#syntax_6)
* [Command Fields](#command-fields_6)
* [Returns](#returns_6)
* [mxsUpdateUser](#mxsupdateuser)
* [Definition](#definition_7)
* [mxsUpdateUser](#mxsupdateuser_1)
* [Syntax](#syntax_7)
* [Command Fields](#command-fields_7)
* [Returns](#returns_7)root35INSERTordereddefault[TheService]
type=service
...
[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
nosqlprotocol.user=the_user
nosqlprotocol.password=the_password
port=17017maxctrl create listener TheService MongoDB-Listener --protocol=nosqlprotocol 'nosqlprotocol={"user":"the_user", "password": "the_password"}'const uri = "mongodb://127.0.0.1:17017"$ mongo --host 127.0.0.1 --port 17017
MongoDB shell version v4.4.1
...
>MariaDB [(none)]> select user, host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| bob | % |
| mysql | localhost |
+-------------+-----------+
2 rows in set (0.001 sec)> use test;
switched to db test
> db.runCommand({createUser: "bob", pwd: "bobspwd", roles: []});
{ "ok" : 1 }MariaDB [(none)]> select user, host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| bob | % |
| test.bob | % |
| mysql | localhost |
+-------------+-----------+
3 rows in set (0.001 sec)> use mariadb
switched to db mariadb
> db.runCommand({createUser: "bob", pwd: "bobspwd", roles: []});
{
"ok" : 0,
"errmsg" : "User \"bob\" already exists",
"code" : 51003,
"codeName" : "Location51003"
}> db.runCommand({createUser: "alice", pwd: "alicespwd", roles: []});
{ "ok" : 1 }MariaDB [(none)]> select user, host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| alice | % |
| bob | % |
| test.bob | % |
| mysql | localhost |
+-------------+-----------+
4 rows in set (0.001 sec)...
nosqlprotocol.user=theuser
nosqlprotocol.password=thepasswordnosqlprotocol.authentication_required=truenosqlprotocol.authorization_enabled=truenosqlprotocol.user = user_with_privileges_for_creating_a_user
nosqlprotocol.password = the_users_password$ mongo --port 17017
...
>> use admin;
switched to db admin
> db.runCommand({createUser: "nosql_admin", pwd: "nosql_pwd", roles: ["userAdmin"]});
{ "ok" : 1 }> use mariadb;
switched to db admin
> db.runCommand({mxsAddUser: "bob", pwd: "bob_pwd", roles: ["userAdmin"]});
{ "ok" : 1 }nosqlprotocol.authentication_required=true
nosqlprotocol.authorization_enabled=true> use test;
switched to db test
> db.runCommand({createUser: "alice", pwd: "alices_pwd", roles: []});
{
"ok" : 0,
"errmsg" : "command createUser requires authentication",
"code" : 13,
"codeName" : "Unauthorized"
}[NoSQL-Listener]
...
nosqlprotocol.user=db.the_user
nosqlprotocol.password=the_password
nosqlprotocol.authentication_required=true
nosqlprotocol.authorization_enabled=true
...CREATE USER 'admin.nosql_admin'@'%' IDENTIFIED BY 'nosql_password';
GRANT ALL PRIVILEGES ON *.* TO 'admin.nosql_admin'@'%' WITH GRANT OPTION;[NoSQL-Listener]
type=listener
service=...
protocol=nosqlprotocol
nosqlprotocol.user=admin.nosql_admin
nosqlprotocol.password=nosql_password
nosqlprotocol.authentication_required=true
nosqlprotocol.authorization_enabled=true... notice : [nosqlprotocol] Created initial NoSQL user 'admin.nosql_admin'.$ mongo --quiet --port 17017 -u nosql_admin -p nosql_password admin
>> db.runCommand({usersInfo: 1});
{
"users" : [
{
"_id" : "admin.nosql_admin",
"userId" : UUID("7d921459-3099-42a7-ad06-ed37ac002161"),
"user" : "nosql_admin",
"db" : "admin",
"roles" : [
{
"db" : "admin",
"role" : "dbAdminAnyDatabase"
},
{
"db" : "admin",
"role" : "readWriteAnyDatabase"
},
{
"db" : "admin",
"role" : "userAdminAnyDatabase"
},
{
"db" : "admin",
"role" : "root"
}
],
"mechanisms" : [
"SCRAM-SHA-256"
]
}
],
"ok" : 1
}CREATE USER 'test.test_user'@'%' IDENTIFIED BY 'test_password';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX ON `test`.* TO 'test.test_user'@'%';[NoSQL-Listener]
type=listener
service=...
protocol=nosqlprotocol
nosqlprotocol.user=test.test_user
nosqlprotocol.password=test_password
nosqlprotocol.authentication_required=true
nosqlprotocol.authorization_enabled=true... notice : [nosqlprotocol] Created initial NoSQL user 'test.test_user'.$ mongo --quiet --port 17017 -u test_user -p test_password test
>> db.runCommand({usersInfo: 1});
{
"users" : [
{
"_id" : "test.test_user",
"userId" : UUID("714f35e7-4276-45af-863c-0be4d1f5dd74"),
"user" : "test_user",
"db" : "test",
"roles" : [
{
"db" : "test",
"role" : "readWrite"
}
],
"mechanisms" : [
"SCRAM-SHA-256"
]
}
],
"ok" : 1
}[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
...[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
...[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
nosqlprotocol.user=the_user
nosqlprotocol.password=the_password
nosqlprotocol.on_unknown_command=return_error
...nosqlprotocol.debug=in,out,backCREATE TABLE name (id VARCHAR(35) AS (JSON_COMPACT(JSON_EXTRACT(doc, "$._id"))) UNIQUE KEY,
doc JSON,
CONSTRAINT id_not_null CHECK(id IS NOT NULL));{ <field1>: <value>, <field2>: <value> ... }> db.runCommand({find: "collection", filter: { _id: 4711 }});> db.runCommand({find: "collection", filter: { _id: { $eq: 4711 }}});... WHERE (id = '4711')... WHERE (JSON_EXTRACT(doc, '$._id') = 4711)updates: [
{
q: <query>,
u: { $set: { status: "D" } },
...
},
...
]updates: [
{
q: <query>,
u: { status: "D", quantity: 4 },
...
},
...
]{ ok: 1 }> use myDatabase;
> db.runCommand({createUser: "user1", pwd: "pwd1", roles: []});{
"ok" : 0,
"errmsg" : "not running with --replSet",
"code" : 76,
"codeName" : "NoReplicationEnabled"
}{ "ok" : 1 }{
"errmsg" : "fsync not supported by MaxScale:nosqlprotocol",
"code" : 115,
"codeName" : "CommandNotSupported",
"ok" : 0
}{ "ok" : 1 }{ "state" : "undecided", "ok" : 1 }db.runCommand(
{
mxsAddUser: "<name>",
pwd: passwordPrompt(), // Or "<cleartext password>"
customData: { <any information> },
roles: [
{ role: "<role>", db: "<database>" } | "<role>",
...
],
mechanisms: [ "<scram-mechanism>", ...],
digestPassword: <boolean>
}
)> db.runCommand({mxsAddUser: "user", pwd: "pwd", roles: ["readWrite"]});
{ "ok" : 1 }> db.runCommand({mxsAddUser: "user2", pwd: "pwd2", roles: ["redWrite"]});
{
"ok" : 0,
"errmsg" : "No role named redWrite@test",
"code" : 31,
"codeName" : "RoleNotFound"
}db.adminCommand(
{
mxsCreateDatabase: <name>
}
)> db.adminCommand({mxsCreateDatabase: "db"});
{ "ok" : 1 }> db.adminCommand({mxsCreateDatabase: "db"});
{
"ok" : 0,
"errmsg" : "The database 'db' exists already.",
"code" : 48,
"codeName" : "NamespaceExists"
}db.runCommand(
{
mxsDiagnose: <command>
}
)> db.runCommand({mxsDiagnose: {ping:1}});
{ "kind" : "immediate", "response" : { "ok" : 1 }, "ok" : 1 }
> db.runCommand({mxsDiagnose: {find:"person", filter: { name: "Bob"}}});
{
"kind" : "single",
"sql" : "SELECT doc FROM `test`.`person` WHERE ( JSON_EXTRACT(doc, '$.name') = 'Bob') ",
"ok" : 1
}
> db.runCommand({mxsDiagnose: {delete:"person", deletes: [{q: { name: "Bob"}, limit:0}, {q: {name: "Alice"}, limit:0}]}});
{
"kind" : "single",
"sql" : [
"DELETE FROM `test`.`person` WHERE ( JSON_EXTRACT(doc, '$.name') = 'Bob') ",
"DELETE FROM `test`.`person` WHERE ( JSON_EXTRACT(doc, '$.name') = 'Alice') "
],
"ok" : 1
}db.runCommand(
{
mxsGetConfig: <any>
});> db.runCommand({mxsGetConfig: 1});
{
"config" : {
"on_unknown_command" : "return_error",
"auto_create_tables" : true,
"id_length" : 35
...
},
"ok" : 1
}db.runCommand(
{
mxsListTables: <any>
});> db.runCommand({mxsListTables:"hello"});
{
cursor: {
id: Long('0'),
ns: 'test.$cmd.mxsListTables',
firstBatch: [
{ name: 'Cars', nosql: true },
{ name: 'Customers', nosql: false },
]
},
ok: 1
}db.runCommand(
{
mxsRemoveUser: "<name>"
}
)> db.runCommand({mxsRemoveUser: "user"});
{ "ok" : 1 }> db.runCommand({mxsRemoveUser: "user"});
{
"ok" : 0,
"errmsg" : "User 'user@test' not found",
"code" : 11,
"codeName" : "UserNotFound"
}db.runCommand(
{
mxsSetConfig: document
});> db.runCommand({mxsGetConfig: 1});
{
"config" : {
"on_unknown_command" : "return_error",
"auto_create_tables" : true,
"id_length" : 35
...
},
"ok" : 1
}
> db.runCommand({mxsSetConfig: { auto_create_tables: false}});
{
"config" : {
"on_unknown_command" : "return_error",
"auto_create_tables" : false,
"id_length" : 35
...
},
"ok" : 1
}db.runCommand(
{
mxsUpdateUser: "<name>",
pwd: passwordPrompt(), // Or "<cleartext password>"
customData: { <any information> },
roles: [
{ role: "<role>", db: "<database>" } | "<role>",
...
],
mechanisms: [ "<scram-mechanism>", ...],
digestPassword: <boolean>
}
)> db.runCommand({mxsUpdateUser: "user", pwd: "pwd", roles: ["readWrite"]});
{ "ok" : 1 }> db.runCommand({mxsUpdateUser: "user", roles: ["redWrite"]});
{
"ok" : 0,
"errmsg" : "No role named redWrite@test",
"code" : 31,
"codeName" : "RoleNotFound"
}[My-NoSQL-Listener]
...
nosqlprotocol.internal_cache=cache[My-NoSQL-Listener]
...
nosqlprotocol.internal_cache=cache
nosqlprotocol.cache.max_size=10M
nosqlprotocol.cache.soft_ttl=30s
nosqlprotocol.cache.hard_ttl=40s
...[TheService]
type=service
...
[NoSQL-Listener]
type=listener
service=TheService
protocol=nosqlprotocol
nosqlprotocol.user=the_user
nosqlprotocol.password=the_password
port=17017... notice : (NoSQL-Listener); Listening for connections at [127.0.0.1]:17017$ mongo --port 17017
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:17017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("694f3eed-329f-487a-8d73-9a2d4cf82d62") }
MongoDB server version: 4.4.1
---
...
---
>> db.runCommand({insert: "collection", documents: [{_id: 1, "hello": "world"}]});
{ "n" : 1, "ok" : 1 }> db.runCommand({find: "collection"});
{
"cursor" : {
"firstBatch" : [
{
"_id" : 1,
"hello" : "world"
}
],
"id" : NumberLong(0),
"ns" : "test.collection"
},
"ok" : 1
}MariaDB [(none)]> select * from test.collection;
+------+------------------------------------+
| id | doc |
+------+------------------------------------+
| 1.0 | { "_id" : 1.0, "hello" : "world" } |
+------+------------------------------------+> db.runCommand({mxsDiagnose: {insert: "collection", documents: [{_id: 1, "hello": "world"}]}});
{
"kind" : "multi",
"sql" : [
"INSERT INTO `test`.`collection` (doc) VALUES ('{ \"_id\" : 1.0, \"hello\" : \"world\" }')"
],
"ok" : 1
}> db.runCommand({mxsDiagnose: {find: "collection"}});
{
"kind" : "single",
"sql" : "SELECT doc FROM `test`.`collection` ",
"ok" : 1
}const uri = "mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority";const uri = "mongodb://<maxscale-ip>:17017";const { MongoClient } = require("mongodb");
const uri = "mongodb://127.0.0.1:17017";
const client = new MongoClient(uri, { useUnifiedTopology: true });
async function run() {
try {
await client.connect();
const database = client.db("mydb");
const movies = database.collection("movies");
// create a document to be inserted
const movie = { title: "Apocalypse Now", director: "Francis Ford Coppola" };
const result = await movies.insertOne(movie);
console.log(
`${result.insertedCount} documents were inserted with the _id: ${result.insertedId}`,
);
} finally {
await client.close();
}
}
run().catch(console.dir);$ nodejs insert.js
1 documents were inserted with the _id: 60afca73bf486114e3fb48b8const { MongoClient } = require("mongodb");
const uri = "mongodb://127.0.0.1:17017";
const client = new MongoClient(uri, { useUnifiedTopology: true });
async function run() {
try {
await client.connect();
const database = client.db("mydb");
const movies = database.collection("movies");
// Query for a movie that has the title 'Apocalypse Now'
const query = { title: "Apocalypse Now" };
const options = {
// Include only the 'director' field in the returned document
projection: { _id: 0, director: 1 },
};
const movie = await movies.findOne(query, options);
// Returns a document and not a cursor, so print directly.
console.log(movie);
} finally {
await client.close();
}
}
run().catch(console.dir);$ nodejs find.js
{ director: 'Francis Ford Coppola' }