Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/snowch/cloudant-java-query-examples


https://github.com/snowch/cloudant-java-query-examples

Last synced: about 5 hours ago
JSON representation

Awesome Lists containing this project

README

        

A few test cases for Cloudant Java
--

- Copy cloudant.properties_template to cloudant.properties
- Add your Cloudant credentials to cloudant.properties
- Create a database with the following documents:

```
{
"_id": "68",
"name": "Peanut butter",
"title": "Peanut butter is the name",
"description": "Peanut butter is the description",
"prices": [
{
"storeName": "Morrisons",
"price": 97
},
{
"storeName": "Saintburrys",
"price": 72
},
{
"storeName": "Tesco",
"price": 79
}
],
"rev": null
}

{
"_id": "69",
"name": "Beans",
"title": "Beans is the name",
"description": "Beans is the description",
"prices": [
{
"storeName": "The Health Food Shop",
"price": 97
}
],
"rev": null
}
```

- Create views:

```
{
"_id": "_design/ddoc",
"_rev": "12-c8b90da86721e12b647e8bdb9ddf37ab",
"views": {
"find-by-product-name": {
"map": "function (doc) {
if (doc.name) {
emit(doc.name, null);
}
}"
},
"find-by-store-name": {
"map": "function (doc) {
var shop, price, storename,storeprice;
if (doc.name && doc.prices) {
for (shop in doc.prices) {
storename = doc.prices[shop].storeName;
storeprice = doc.prices[shop].price;
emit(storename, storeprice);
}
}
}"
}
},
"indexes": {
"find-by-store-name": {
"analyzer": "keyword",
"index": "function (doc) {
var shop, price, storename;
if (doc.name && doc.prices) {
for (shop in doc.prices) {
storename = doc.prices[shop].storeName;
index(\"storename\", storename, {\"store\": true});
}
}
}"
}
}
}
```

- Run tests:

```
./gradlew check
```