toArray

ReQL command: toArray

Command syntax

cursor.toArray(callback)
array.toArray(callback)
cursor.toArray() → promise
array.toArray() → promise

Description

Retrieve all results and pass them as an array to the given callback.

Note: Because a feed is a cursor that never terminates, calling toArray on a feed will throw an error. See the changes command for more information on feeds.

Example: For small result sets it may be more convenient to process them at once as an array.

cursor.toArray(function(err, results) {
    if (err) throw err;
    processResults(results);
});

The equivalent query with the each command would be:

var results = []
cursor.each(function(err, row) {
    if (err) throw err;
    results.push(row);
}, function(err, results) {
    if (err) throw err;
    processResults(results);
});

An equivalent query using promises.

cursor.toArray().then(function(results) {
    processResults(results);
}).error(console.log);

Related commands

Get more help

Couldn't find what you were looking for?

© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/javascript/to_array/

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部