rql get multiple documents from list of keys rethinkdb in javascript

后端 未结 4 1986
广开言路
广开言路 2021-01-05 00:16

I have a table of \"person\" data, which has a unique key \"id\". I have a list of id\'s that I want to get the data for which I\'ll be sending as a JSON array from the cli

4条回答
  •  旧时难觅i
    2021-01-05 00:28

    short answer:

    r.expr([id1, id2, id3]).eqJoin(function(doc) { return doc; }, r.table("person"))
    

    Longer answer:

    There are a couple of ways to do this. The above is what I'd call the canonical way. Let's breakdown what's happening:

    First with r.expr([id1, id2, id3]) we're packaging up the array to send it over to the server.

    Then we call eqJoin what it does is take a stream of values and dispatch and indexed get for each one. The function(doc) { return doc; } is a slightly ugly hack because eqJoin requires a mapping function.

    So in the end the above code becomes equivalent to:

    [r.table("person").get(id1), r.table("person").get(id2), r.table("person).get(id3)]
    

提交回复
热议问题