Xenioo Database Collection Methods
The Xenioo connection object represent a connection instance to your chatbot database. The following methods are exposed by the connection object to interact with your data.

Connect

Returns a virtual Xenioo database instance that can be further used to manipulate remote data.
1
var connection = conversation.Connect();
Copied!

Save

This method will insert or update a record in the specified collection. The collection must first be created in the Database Collections interface. Objects should be supplied as standard JS objects.
1
database.Save( collection, object );
Copied!
If the object contains an _id field, Xenioo will attempto to update the record, overwriting it.
The following example will save a new record inside the users collection:
1
var id = database.Save( "users", {
2
first_name:'Mario',
3
last_name:'Rossi',
5
enabled:true
6
} );
7
8
/* the id var now contains the unique id of the object */
9
Copied!

Update

This method will update a record in the specified collection. The collection must first be created in the Database Collections interface. Objects should be supplied as standard JS objects.
1
database.Update( collection, documentid, object );
2
database.Update( collection, documentid, object, updatemode );
Copied!
This method will use all of the fields of the supplied object ot update the target record. If the field does not exist in the target record, it will be created.
Update mode can be one of the following values:
Value
Description
OVW
Overwrites the contents of field with the new value
ADD
Adds a value to the current field value
SUB
Subtracts a value from the current field value
The following example will update a field for a user in the example users collection:
1
database.Update( "users", { enabled:false }, "<record id>", "OVW" );
Copied!

Delete

Deletes one or more records from a collection, using the specified filters.
1
database.Delete( collection, filter );
Copied!
If filter contains a record unique id, only that specific record will be deleted. If filter contains instead a supported URL Filter it will delete all the affected records.
The following example deletes a single record from the example users collection:
1
var deletedcount = databae.Delete( "users", "<record id>" );
Copied!
The following example instead will delete all users who are not enabled from the example users collection:
1
var deletedcount = databae.Delete( "users", "enabled[EQL]false" );
Copied!

Load

This method will load a single record from a collection
1
database.Load( collection, filter );
Copied!
If filter contains a record unique id, only that specific record will be loaded. If filter contains instead a supported URL Filter the first record that matches the filter will be returned

Query

This method will open a cursor pointing to a list of all the objects that are currently stored in the specified collection that matches the given filter
1
database.Query( collection, filter );
Copied!
Filter can contain a valid URL Filter or be empty. An empty filter will return a cursor pointing to all records in the collection.
This method does not return any actual data. It must be used together with a loop with Read.

Read

This method will read the next available record in the current cursor opened with Query.
1
var obj = database.Read();
Copied!
In the following example, our cloud script will loop on all records inside the users collection that are not enabled:
1
databae.Query( "users", "enabled[EQL]false" );
2
var record = database.Read();
3
while( record != null ){
4
//Do something with the record.
5
conversation.Log( JSON.stringify( record ) );
6
//Read the next one
7
record = database.Read();
8
}
Copied!
Last modified 6mo ago