I am unable to get the ORDER BY to work correctly in Couchbase Server 4.5
Documents
{ "name": "Green", "price": "156" }
{ "name": "Yellow", "price": "175" }
{ "name": "Red", "price": "1" }
{ "name": "Blue", "price": "18" }
PHP
$cluster = new CouchbaseCluster('http://127.0.0.1:8091');
$bucket = $cluster->openBucket('products');
$bucket->enableN1ql(array('http://127.0.0.1:8093'));
$query = CouchbaseN1qlQuery::fromString("SELECT * FROM products ORDER BY price ASC");
$results = $bucket->query($query);
foreach ($results as &$r) {
$name = $r->products->name;
$price = $r->products->price;
echo "$name: $price <br>";
}
Output
Red: 1
Green: 156
Yellow: 175
Blue: 18
Please will you let me know how I can tell Couchbase that the price field is an integer so the order will be done correctly.