In the previous blog post we explained how to create schemas and collections. In this one we are going to explain how to work with collections: adding, updating and deleting documents.
The following code demonstrates how to add a single document to an existing collection:
var mysqlx = require('mysqlx');
mysqlx.getSession({
host: 'host',
port: '33060',
dbUser: 'root',
dbPassword: 'my pass'
}).then(function (session) {
var schema = session.getSchema('mySchema');
var coll = schema.getCollection('myColl');
var newDoc = { name: 'Test Name', description: 'Test Description' };
coll.add(newDoc).execute().then(function (added) {
console.log('Document(s) added: '
+ added.getAffectedItemsCount());
session.close();
})
.catch(function (err) {
console.log(err.message);
console.log(err.stack); …[Read more]