Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

orientjs - how to perform bulk insert

orientdb.insert()
        .into('User')
        .set({name: 'John', surname: 'Smith'})
        .all()
        .then(function(result) {
  ...
}, function(error){
  ...
})

This is the way to insert a single vertex in OrientDb via orientjs. How to insert multiple objects at once?

The following query

orientdb.insert()
        .into('User')
        .set([{name: 'John', surname: 'Smith'}, {name: 'Harry', surname: 'Potter'}])
        .all()
        .then(function(result) {
      ...
    }, function(error){
      ...
    })

inserts only the last element ({name: 'Harry', surname: 'Potter'})

like image 769
Kiril Kirilov Avatar asked Mar 04 '26 02:03

Kiril Kirilov


1 Answers

You could also use the LET statement:

var OrientDB = require('orientjs');

var server = OrientDB({
    host: 'localhost',
    port: 2424,
    username: 'root',
    password: 'root'
});

var db = server.use({
    name: 'OrientJStest',
    username: 'root',
    password: 'root'
});

db.let('insert',function(i) {
            i
                .insert()
                .into('Person')
                .set({'name':'John'});
        })
        .let('insert2',function(i2) {
            i2
                .insert()
                .into('Person')
                .set({'name':'Harry'});
        })
        .commit()
        .all();

db.select().from('Person').all()
    .then(function (vertex) {
        console.log('Vertexes found: ',vertex);
});

OUTPUT:

Vertexes found:  [ { '@type': 'd',
    '@class': 'Person',
    name: 'John',
    '@rid': { [String: '#12:0'] cluster: 12, position: 0 },
    '@version': 1 },
  { '@type': 'd',
    '@class': 'Person',
    name: 'Harry',
    '@rid': { [String: '#12:1'] cluster: 12, position: 1 },
    '@version': 1 } ]

OUTPUT (STUDIO):

enter image description here

Hope it helps

like image 106
LucaS Avatar answered Mar 09 '26 01:03

LucaS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!