Re: insert performance issue
Hi Eric,
as mentioned in the documentation (https://dev.mysql.com/doc/dev/connector-nodejs/8.0/tutorial-Prepared_Statements.html) at the moment, the X DevAPI connector for Node.js (or any other X DevAPI/X Protocol implementation) does not support prepared statements for SQL statements (Session.sql() -> Mysqlx.Sql.StmtExecute) and CRUD inserts (Collection.add() and Table.insert() -> Mysqlx.Crud.Insert). Which, coincidentially, are exactly the APIs that would suite your needs.
This is a known limitation, but in any case, I suggest you submit an enhancement request using our public bug tracker (http://bugs.mysql.com/) using the "MySQL Connectors: Document Store: DevAPI" category.
With regards to performance, I've tested similar workloads to yours using the X DevAPI connector for Node.js and some other community drivers that use the classic protocol, and the results (while not using prepared statements) are similar. Maybe you can point me to an even more specific situation where that might not be the case.
Some other things that caught my eye. Due to the way that .bind() works with SQL statement parameters (ordinal and cumulative by nature), you cannot re-use the same statement instance ("command" in your case) to execute different queries. It will only use the values you provided in the first run and then will start to hit a "Too many arguments" error reported by the server.
This is more like a Node.js-specific behaviour (for instance, with the MySQL Shell that does not happen), so I would say it probably can be improved. Once again, I would suggest you submit a bug report using our public bug tracker, this time using the "Connector for Node.js" category.
Also, I'm not a schema design expert, but maybe using a traditional relational table to store logs, which I guess is what you want/need, and are kind of unstructured by nature, might not be the best approach. Have you considered or tried just saving them in JSON instead? Maybe it yields better results.
Hope it helps.
Thanks