2017-08-16 9 views
0

私は、OrientJsを使用して、node.jsからOrientDBと通信しています。 私は、彼が存在するかどうかをチェックした後、新しいユーザーをdbに挿入するAPIを実装しました。 fetcher.userExists(db, username, password)OrienDb.RequestError:未知のセッションが見つかりましたx

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

// Connect to db 'test' 
var db = dbServer.use({ 
    name: 'mydbtest', 
    username: 'root', 
    password: 'my_root_password' 
}) 

// Set the server... 

app.post('/insertUser/', function (req, res) { 
    let username = req.body.username 
    let password = req.body.password 

    //Checks on username and password ... 

    let fetcher = require('../fetcher/fetcher') 
    fetcher.userExists(db, username, password).then(function (exists) { 
     console.log(exists) //exists = true/false 
     if (!exists) { 
      db.open().then(
       db.let('user', function (user) { 
        user.create('vertex', 'User') 
         .set({ 
          username: username, 
          password: password 
         }) 
       }).commit().return('$user').one().then(function (result) { 
        db.close() 
        if (!result.undefined) { res.status(200).send(true) } 
        else { res.status(200).send(false) } 
       }).catch(function (e) { // The error is caught here 
        db.close() 
        console.error(e); 
        res.status(500).send({ message: 'Unable to save new user1' }) 
       }) 
      ).catch(function (e) { 
       db.close() 
       res.status(500).send({ message: 'Unable to save new user' }) 
      }) 
     } 

     else res.status(200).send(false) 
    }) 
}) 

はそうでない場合はfalse、ユーザーが存在しない場合にtrueを返す関数です。ポストマンからTHI APIを呼び出すとき 、私はこのエラーメッセージが表示されます。

{ OrientDB.RequestError 
at child.Operation.parseError (C:\Users\sdp\node_modules\orientjs\lib\transport\binary\protocol33\operation.js:896:13) 
at child.Operation.consume (C:\Users\sdp\node_modules\orientjs\lib\transport\binary\protocol33\operation.js:487:35) 
at Connection.process (C:\Users\sdp\node_modules\orientjs\lib\transport\binary\connection.js:410:17) 
at Connection.handleSocketData (C:\Users\sdp\node_modules\orientjs\lib\transport\binary\connection.js:301:20) 
at emitOne (events.js:115:13) 
at Socket.emit (events.js:210:7) 
at addChunk (_stream_readable.js:252:12) 
at readableAddChunk (_stream_readable.js:239:11) 
at Socket.Readable.push (_stream_readable.js:197:10) 
at TCP.onread (net.js:588:20) 
name: 'OrientDB.RequestError', 
message: 'Found unknown session 13', 
data: {}, 
previous: [], 
id: 1, 
type: 'com.orientechnologies.common.io.OIOException', 
hasMore: 0 } 

メッセージがFound unknown session 13ですが、それは2で、私はサービスを呼び出すたびに数が増えます。

文のコードをthenブロックのfetcher.userExists(db, username, password).then(function (exists) {..のブロックに入れても問題ありませんが、そうすることでユーザーが存在するかどうかを確認できます。私は問題が何かを理解することができます。誰か助けてくれますか?ありがとう。

注:私はこの方法で私は私が同様の方法で(ユーザーが存在するかどうかを見つけるために問い合わせをした、問題はfetcher.userExists(db, username, password)でDB接続したOrientDBコミュニティに2.2.24

+0

こんにちは、あなたのセッションが切れてしまったり、一時的に切断されたりする可能性はありますか? –

答えて

0

を使用しています私が掲載したコードで)。だから、私はdb.open()との接続を開いて、結果を返す前に、私はそれを単に閉じてdb.close()を閉じた。私はそれを適切に閉じなかった。私は新しい接続を開き、古いものがクローズされる前に、クエリを実行しようとしたようだったfetcher.userExists(db, username, password)で接続を開いた後、そう

//... 
if (!exists) { 
    db.open().then(
     db.let('user', function (user) { 
      user.create('vertex', 'User') 
       .set({ 
        username: username, 
        password: password 
       }) 
     }).commit().one().then(function (result) { 
      db.close().then(function(){  // <--- ADD then BLOCK HERE 
       if (!result.undefined) { res.status(200).send(true) } 
       else { res.status(200).send(false) } 
      }) 
     }) 
    }) 
} 

db.close()後のコードは次のように、thenブロックにする必要があります。 db.close()の後にコードをthen()に置くことでこれを回避できます。

関連する問題