Forum BigDB How do you use compound indexes?

Discussion and help relating to the PlayerIO database solution, BigDB.

How do you use compound indexes?

Postby robertflesch » September 24th, 2014, 4:35 pm

I have been searching the net for some examples of how to use indexes, but I can't find any that fit my case (or maybe I just don't get them yet).

lets say I have a table "Objects" with three properties.
owner:String
canCopy:Boolean
image:ByteArray

I have created an index called ownerCanCopy
ownerCanCopy (edit index, delete) Status from 8 hours ago: 2 entries total using 102 bytes
owner (String, Ascending)
copy (Boolean, Ascending)

now I want to filter the results where
owner = "Bob" and canCopy = true;

var canCopy:Boolean = true;
PlayerIO.BigDB.loadRange( "Objects"
, "ownerCanCopy"
, ["Bob"]
, canCopy
, null
, 100
, some function...
, some function... );
works, but if I set canCopy to false.
I get back both the true AND false result.
Why is that???

examples show
//Load all users from Paris that are 30 years old, and were created in April
PlayerIO.BigDB.LoadRange("Users", "ByLocationAgeCreated",
new object[]{"Paris", 30}, new DateTime(2010, 4, 1),
new DateTime(2010, 4, 30), 100,
delegate(DatabaseObject[] result) {
//...
}
);

and if I try to create an object to pass in, I get an error.
[{owner:"Bob", copy:true}]
Results in
Error: Property no. 1 in index 'ownerCanCopy' is of type: String, and not of type: Obj

So I can make this work for 2 indexes, if I only need the cases where it is true.
Why can't I pass in a compound index in the $path like they show in the examples?

Also what if I had 3 fields in my index? How would you access that?
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm

Re: How do you use compound indexes?

Postby Henrik » October 13th, 2014, 5:30 am

The path argument takes all columns of the index that have a single value, and the start and stop arguments are for the next column, and the range of values you want.

Note that the path argument is an array, not an object, it simply takes the values of the columns, in the order they're specified in the index.

So in your case, the path should be the array ["Bob", true], and the start and stop values should be left empty.
Henrik
.IO
 
Posts: 1822
Joined: January 4th, 2010, 1:53 pm

Re: How do you use compound indexes?

Postby robertflesch » October 16th, 2014, 4:45 pm

Thx Henrik
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm


Return to BigDB



cron