Find Document By Key Value with multiple Keys and Values

0 votes
Hi, I have tried to find an answer to this question for some time but can't find an answer..

Is it possible to use FindDocumentByKeyValue with multiple keys and corresponding values? If yes, how do you set your keys and values? I am using Swift by the way.
 
let keys = ....
let values = ....

Best regards

Erik
asked Aug 8, 2016 in iOS by erijo368 (15 points)

1 Answer

0 votes
 
Best answer

Hi,

Yes, it is possible to find document with multiple keys and values. You have to use FindDocumentByQuery for the same as follows:

        let key1 = "name"
        let value1 = "Nick"
        
        let key2 = "age"
        let value2 = 30
        
        let query1 = QueryBuilder.buildQueryWithKey(key1, value: value1, andOperator:APP42_OP_EQUALS)
        let query2 = QueryBuilder.buildQueryWithKey(key2, value: value2, andOperator:APP42_OP_EQUALS)
        let query3 = QueryBuilder.combineQuery(query1, withQuery: query2, usingOperator: APP42_OP_AND)
        
        storageService?.findDocumentsByQuery(query3,dbName:dbName, collectionName: collectionName, completionBlock: { (success, response, exception) -> Void in
            if(success)
            {
                let storage = response as! Storage
                NSLog("%@", storage.dbName)
                NSLog("%@", storage.collectionName)
                let jsonDocList = storage.jsonDocArray
                for jsonDoc in jsonDocList {
                    NSLog("%@",jsonDoc.docId)
                    NSLog("%@",jsonDoc.createdAt)
                    NSLog("%@",jsonDoc.updatedAt)
                    NSLog("%@",jsonDoc.jsonDoc)
                }
            }
            else
            {
                NSLog("%@", exception.reason!)
                NSLog("%d", exception.appErrorCode)
                NSLog("%d", exception.httpErrorCode)
            }
    })

Let me know if you have any further queries.

answered Aug 9, 2016 by rajeev.etc (1,629 points)
selected Aug 9, 2016 by erijo368
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...