Tutorial: Browse data

Serverless DatabaseData Structure Browse data

Before doing any operation on a Webcom database, you need a Webcom reference, which provides a pointer to a location or a data node inside your database tree. When creating a new Webcom reference, it points to the root node of the specified Webcom application:

var sampleChatRef = new Webcom('samplechat');
Webcom sampleChatRef = new Webcom(new WebcomApp("samplechat"));

Coming soon!
In the meanwhile, refer to the iOS API reference

Creating a Webcom reference is an extremely light-weight operation, so you can create as many as you like without worrying about wasting bandwidth or memory.

Webcom references then come with a couple of methods to easily navigate through the tree-like structure of the data.

child() method

First, each reference provides a function that takes the relative path to a child and returns a reference pointing to this child node

var childRef = sampleChatRef.child('users');
Webcom childRef = sampleChatRef.child("users");

Coming soon!
In the meanwhile, refer to the iOS API reference

The child() method accept several path segments separated by slashes (/), as well as usual "." and ".." segments to browse relatively within the data tree hierarchy:

var otherRef = sampleChatRef.child('users/mary/../john');
Webcom otherRef = sampleChatRef.child("users/mary/../john");

Coming soon!
In the meanwhile, refer to the iOS API reference

parent() method

Second, each reference provides a function that returns a reference to its parent node, or null if the reference already points to the data root node.

var parentRef = childRef.parent();
// parentRef and sampleChatRef now point to the same node.
Webcom parentRef = childRef.parent();
// parentRef and sampleChatRef now point to the same node.

Coming soon!
In the meanwhile, refer to the iOS API reference

Examples

Here are several ways of creating a reference that points to the same Webcom data node.

var usersRef = sampleChatRef.child('users');
var fredRef = usersRef.child('fred');
// is equivalent to:
var fredRef = sampleChatRef.child('users/fred');

var messageListRef = fredRef.parent().parent().child('message_list');
// is equivalent to:
var messageListRef = new Webcom('samplechat').child('message_list');
var messageListRef = fredRef.child('../../message_list');
Webcom usersRef = sampleChatRef.child("users");
Webcom fredRef = usersRef.child("fred");
// is equivalent to:
Webcom fredRef = sampleChatRef.child("users/fred");

Webcom messageListRef = fredRef.parent().parent().child("message_list");
// is equivalent to:
Webcom messageListRef = new Webcom(new WebcomApp("samplechat")).child("message_list");
Webcom messageListRef = fredRef.child("../../message_list");

Coming soon!
In the meanwhile, refer to the iOS API reference

Note that the behaviors of the child and parent methods differ when applied on the reference pointing to the data root node:

sampleChatRef.child('..');
// => returns sampleChatRef
sampleChatRef.parent();
// => returns null
sampleChatRef.child("..");
// => returns sampleChatRef
sampleChatRef.parent();
// => returns null

Coming soon!
In the meanwhile, refer to the iOS API reference

Once you have a Webcom reference, you can use it to write, read and query the corresponding data node within your data tree using the other Webcom API functions.