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'})
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):

Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With