Performing string operations
ReQL provides the following functions to manipulate and search strings:
Match()
takes a string or a regular expression as an input and performs a search over the field. If it matches, it returns the data in thecursor
, which we can loop over to retrieve the actual data.For example, we have to find all the users whose name starts with
J
. Here is the query for the same:
rethinkdb.table("users").filter(function(user) { return user("name").match("^J"); }).run(connection,function(err,cursor) { if(err) { throw new Error(err); } cursor.toArray(function(err,data) { console.log(data); }); });
Here we are first performing a filter, and inside it, we put our
match()
condition. The filter gives every document to thematch()
function and it appends it to thecursor
. Upon running, you should be able to view the users with names starting withJ
.split...