I am building a chat application with Kinvey mbaas as database. I have a collection storing chats with the following data columns: _id, firstUser, otherUsers, history. So far the idea is: when a message is posted GET is requested to find if there is chat between the two users. GET takes the whole collection and iterates over entries and checks if firstUser and otherUsers match. This is where the problem comes: they don't match ever. Code bellow:
for (let entity = 0; entity < response.length; entity++) {
console.log('DEV_firstUser: '
+ response[entity]['firstUser'] + '|' + firstUser);
console.log('DEV_otherUsers: |'
+ response[entity]['otherUsers'] + '|' + otherUsers + "|");
console.log(response[entity]['firstUser'] === firstUser);
console.log(response[entity]['otherUsers'] === otherUsers);
// The problematic condition - the logs above are demonstrations.
if (response[entity]['firstUser'] === firstUser
&& response[entity]['otherUsers'] === otherUsers) {
id = response[entity]['_id'];
console.log('DEV_id: ' + id);
index = entity;
console.log(response[index][id]);
}
}
'response' is the collection - array of objects from what I can see. 'entity' is straightforward - each entity inside the collection. 'otherUsers' is array.
This is what I get on the console:
DEV_firstUser: alex|alex
DEV_otherUsers:|Ganka|Ganka|
true
false