2016-11-23 3 views
3

私はrethinkDBに新しく、フィルター機能を使用してユーザー名でデータを検索しようとしています。 しかし、rethinkDBはデータが存在してもnullイベントを返します。Rethinkdbクエリは常にnullを返します。

を更新しました

//Define Your Api//Define Your Api 
import express from 'express'; 
import r from 'rethinkdb'; 



const router = express.Router(); 


router.post('/users',(req,res)=>{ 

    let username = req.body.data.username; 
    let password = req.body.data.password; 
    console.log(username,password); 

    r.connect({db:"image"}).then((conn) => { 
     r.table("users").filter({username:"arfo"}).run(conn,function (err, data) { 
      console.log(data) //null 
     }) 
    }) 


}); 


export default router 

それは私にこのようなデータの束を返す私は、このデータを操作するために

Cursor { 
    _type: 3, 
    _eachCb: [Function], 
    _conn: 
    TcpConnection { 
    host: 'localhost', 
    port: 28015, 
    db: 'image', 
    authKey: '', 
    timeout: 20, 
    ssl: false, 
    outstandingCallbacks: {}, 
    nextToken: 2, 
    open: true, 
    closing: false, 
    buffer: <Buffer >, 
    _events: {}, 
    _eventsCount: NaN, 
    _closePromise: null, 
    rawSocket: 
     Socket { 
     connecting: false, 
     _hadError: false, 
     _handle: [Object], 
     _parent: null, 
     _host: 'localhost', 
     _readableState: [Object], 
     readable: true, 
     domain: null, 
     _events: [Object], 
     _eventsCount: 7, 
     _maxListeners: undefined, 
     _writableState: [Object], 
     writable: true, 
     allowHalfOpen: false, 
     destroyed: false, 
     _bytesDispatched: 325, 
     _sockname: null, 
     _pendingData: null, 
     _pendingEncoding: '', 
     server: null, 
     _server: null, 
     user: 'admin', 
     password: '', 
     read: [Function], 
     _consuming: true } }, 
    _token: 1, 
    _opts: {}, 
    _root: { [Function] args: [ [Object], [Object] ], optargs: {} }, 
    _responses: [ { t: 2, r: [Object], n: [] } ], 
    _responseIndex: 0, 
    _outstandingRequests: 0, 
    _iterations: 0, 
    _endFlag: true, 
    _contFlag: false, 
    _closeAsap: false, 
    _cont: null, 
    _cbQueue: [], 
    _closeCb: null, 
    _closeCbPromise: null, 
    next: [Function] } 

答えて

3

RethinkDB docsから持っていない、それはrun戻り(err, data)のように見えます。あなたがあなたのコードを更新するのであれば

r.table('marvel').run(conn, function(err, cursor) { 
    cursor.each(console.log); 
}) 

:例えば(ドキュメントから)

r.table("users").filter({username:"arfo"}).run(conn,function (err, data) { 
    console.log(data) 
}) 

その後、それはあなたが見ていたnullログを削除する必要があります。

私はRethinkDBの専門家だが、ドキュメントから、それはあなたが応答からデータを取得したい場合のように、あなたがカーソルの上にtoArrayを呼び出すことができますになります。

r.table("test").run(conn, function(error, cursor) { 
    cursor.toArray(function(error, results) { 
     console.log(results) // results is an array of documents 
    }) 
}) 
+0

そのが動作していないその更新を参照してください。 – Nane

+0

rethinkDBに問題がありますか? – Nane

+0

私は自分の答えを更新しました。カーソル上で 'toArray()'を呼び出す必要があるかもしれないと思います。トラブルシューティングのドキュメントをご覧ください:https://www.rethinkdb.com/docs/troubleshooting/ – dan

関連する問題