I have an app and a list of all the actions a user has done while using it.

To put an example, for each user I have data like this:

  • "start"
  • "country":"aa"
  • "session":"0"
  • "menu":"main"
  • "menu":"play"
  • "play_level":"1"
  • "play_during":"70 seconds"
  • "purchase":"metal hammer"
  • "play_level":"2"

I have to choose a database where I could enter this kind of data, and they, in example, query "all the players that bought the metal hammer before level 2".

This is obviously not a SQL scenario and I have zero experience in NoSQL. I've been examining types of NoSQL databases (column, document, key-value, graph, ...) and I suppose that a key-value DB type is the one I should be using, but I'm not able to find if I can have duplicate keys, and if I can query for entries to appear before other entries (purchase xyz before play_level 2)

Are key-value NoSQL databases able to handle this kind of data and query or should I choose another NoSQL database type?

  • 5
    "This is obviously not a SQL scenario" Why not? Looks like a pretty good SQL scenario to me. – Vincent Savard Jun 7 '17 at 11:12

One can solve this by SQL as @Vincent said, e.g. by having a table with the following fields:

  • userId: whatever
  • timestamp: Date
  • eventName: string
  • params: string or number, maybe multiple fields. NoSQL becomes relevant at this point.

Here's some dummy example to start with, you should refine it though.

SELECT u, e1, e2
FROM users u, events e1, events e2
WHERE e1.userId = u.userId
AND e1.eventName = 'play_level'
AND e1.paramsNumber = 2
AND e2.userId = u.userId
AND e2.eventName = 'purchase'
AND e2.params = 'metal hammer'
AND e2.timestamp < e1.timestamp

Maybe better if using LEFT JOIN, some GROUP BY would be necessay to prevent duplications (e.g. she played level 2 twice). Appropriate indexing (userId, eventName) can get better performance.

BTW I'm using MongoDB in many projects, you can give it a try, it's not that difficult. But note that NoSQL could be your decision, not a functional requirement.

| improve this answer | |
  • Thanks Gábor & Vincent. I didn't thought of structuring the data this way around a timestamp. (honestly I'm not used to databases and except for some SELECTs, most of my knowledge is theoretical from the uni like a thousand years ago :) ) I'll take some time to implementate the solution and will come back to confirm it or update the question. Thanks! – KakCAT Jun 7 '17 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.