io.on('connection', (socket) => { socket.on('login', async ({ user, password }) => { dbconfig.user = user; dbconfig.password = password; try { dbconnect = await mysqlx.getSession(dbconfig); let databases = await dbconnect.getSchemas(); console.log(`Databases`, databases); console.log(`Index 0`, databases[0].name); console.log(`Stringify Data`, JSON.stringify(databases)); socket.emit("DATABASES", JSON.stringify(databases)); } catch (err) { console.log('err', err); socket.emit("ERROR", err); } }); }); 

It seems to return the database normally, but when trying to make a stingifay, for some reason, this is the result.
Also, I can’t refer to which element is valid to 0 and take its name property from it.
I'm using mysql / xdevapi '

enter image description here

    1 answer 1

    According to official documentation, to get the database names:

     // Connecting to MySQL and working with a Session var mysqlx = require('@mysql/xdevapi'); // Connect to a dedicated MySQL server using a connection URI mysqlx .getSession('user:password@localhost') .then(function (mySession) { // Get a list of all available schemas return mySession.getSchemas(); }) .then(function (schemaList) { console.log('Available schemas in this session:\n'); // Loop over all available schemas and print their name schemaList.forEach(function (schema) { console.log(schema.getName() + '\n'); }); }); 

    In your case:

     // Loop over all available schemas and print their name databases.forEach(function (schema) { console.log(schema.getName() + '\n'); }); 

    It seems that you cannot work with Schema Objects received by you as with a javascript object, so JSON.stringify is not appropriate here.

    It describes how to work with such objects and what functions are available: https://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-schema-objects-and-functions.html

    • damn that's why forever, it seems that it should be considered almost in a het-starter, and as a result, almost at the end of the documentation. Sat stuck for 2 days, could not understand what the problem was. - singlesly