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

这是通过 orientjs 在 OrientDb 中插入单个顶点的方法。如何一次插入多个对象?

以下查询

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

仅插入最后一个元素 ( {name: 'Harry', surname: 'Potter'})

4

2 回答 2

1

尝试这个

var OrientDB = require('orientjs');

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

var db = server.use({
  name: 'mydb',
  username: 'admin',
  password: 'admin'
})

db.query('insert into User2(name) values ("John"),("Harry")').then(function (response) {
    console.log(response);
});

server.close();

这是我得到的结果

在此处输入图像描述

希望能帮助到你

于 2016-03-23T14:53:00.383 回答
1

您还可以使用以下LET语句:

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);
});

输出

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 } ]

输出(工作室)

在此处输入图像描述

希望能帮助到你

于 2016-04-09T10:37:03.017 回答