new Collection(collectionID)
Creates a new Collection that represents the server-side collection with the specified collection ID
Parameters:
Name | Type | Description |
---|---|---|
collectionID |
String | The string ID for the collection you want to represent. |
- Source:
Example
var col = cb.Collection("12asd3049qwe834qe23asdf1234");
Methods
-
create(newItem, callback)
-
Creates a new item in the collection and returns the created item to the callback
Parameters:
Name Type Description newItem
Object An object that represents an item that you want to add to the collection callback
function Supplies processing for what to do with the data that is returned from the collection - Source:
Example
Creating a new item in the collection
//This example assumes a collection of items that have the columns: name, height, and age. var newPerson = { name: 'Jim', height: 70, age: 32 }; var callback = function (err, data) { if (err) { throw new Error (data); } else { console.log(data); } }; col.create(newPerson, callback); //this inserts the the newPerson item into the collection that col represents
-
fetch(_query, callback) → {ClearBlade.Item}
-
Reqests an item or a set of items from the collection.
Parameters:
Name Type Description _query
Query Used to request a specific item or subset of items from the collection on the server. Optional. callback
function Supplies processing for what to do with the data that is returned from the collection - Source:
Returns:
An array of ClearBlade Items- Type
- ClearBlade.Item
Example
Fetching data from a collection
var returnedData = []; var callback = function (err, data) { if (err) { throw new Error (data); } else { returnedData = data; } }; col.fetch(query, callback); //this will give returnedData the value of what ever was returned from the server.
-
remove(_query, callback)
-
Removes an item or set of items from the specified collection
Parameters:
Name Type Description _query
Query Query object that used to define what item or set of items to remove callback
function Function that handles the response from the server - Source:
Example
Removing an item in a collection
//This example assumes that you have a collection with the item whose 'name' attribute is 'John' var query = ClearBlade.Query(); query.equalTo('name', 'John'); var callback = function (err, data) { if (err) { throw new Error (data); } else { console.log(data); } }; col.remove(query, callback); //removes every item whose 'name' attribute is equal to 'John'
-
update(_query, changes, callback)
-
Updates an existing item or set of items
Parameters:
Name Type Description _query
Query Query object to denote which items or set of Items will be changed changes
Object Object representing the attributes that you want changed callback
function Function that handles the response of the server - Source:
Example
Updating a set of items
//This example assumes a collection of items that have the columns name and age. var query = ClearBlade.Query(); query.equalTo('name', 'John'); var changes = { age: 23 }; var callback = function (err, data) { if (err) { throw new Error (data); } else { console.log(data); } }; col.update(query, changes, callback); //sets John's age to 23