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 the cursor
, which we can loop over to retrieve the actual data.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); }); });
match()
condition. The filter gives every document to the match()
function and it appends it to the cursor
. Upon running, you should be able to view the users with names starting with J
.split()
takes an optional argument as a separator to filter out the string and returns an array that contains the split part of the string. If no argument is present, it is separated by a space.Suite 300
. If you want to split them by space, you can do so as follows(assuming the same structure of the document as we mentioned previously):rethinkdb.table("users").get('f6f1f0ce-32dd-4bc6-885d 97fe07310845')("address) ("address1").split().run(connection,function(err,result) { if(err) { throw new Error(err); } console.log(result); });
[ 'suite', '300' ] [ 'suite', '300' ]
|
, &
, *
, and so on. You can even provide an optional argument that limits the number of splits.rethinkdb.table("users").get('f6f1f0ce-32dd-4bc6-885d 97fe07310845' ("name").upcase().run(connection,function(err,result) { if(err) { throw new Error(err); } console.log(result); });
You should be receiving the name in uppercase on the console. You can use downcase()
in the same way.
3.142.40.32