1

I am considering using MongoDB for my next project but first I would like to see if it supports functionality that my app will require. So far I didn't see anything in the MongoDB documentation that will be useful for me, but maybe I'm mistaken.

Basically there will be user questionnaire (perhaps hundreds of questions with multiple answer options).

Once a user fills out questionnaire, his answers need to be compared to the answers of all other existing users, some kind of a matching percent need to be calculated and probably saved to the database. The reason I think it needs to be saved to db is that the calculation of the matching percent seem to be a heavy process and I would not want to run it each time a match percent is requested.

So the functionality I'm seeking is:

  • Calling a procedure with a parameter (new userid)
  • In the procedure I need to get all answers of the new user.
  • Run matching code for all existing users' answers against answers of the new user.
  • Saving results back in the database.
  • Doing all of that with one call without having to return data from db to the client app

It is well possible that MongoDB is not the tool for these requirements.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dmitry Efimenko
  • 10,973
  • 7
  • 62
  • 79
  • In fact, MongoDB definitely isn't a good match (and none come to mind that would support your requirements as written). – WiredPrairie Apr 29 '13 at 22:22
  • @WiredPrairie You probably mean 'none but SQL database come to mind'. Any SQL database can do all what I require. However, I afraid SQL database will not perform well with large amounts of users. – Dmitry Efimenko Apr 29 '13 at 23:52
  • Yes, I saw your comment below about "other NoSQL databases" and that's what I was referring to. Of course many SQL options could do what you want. :) – WiredPrairie Apr 30 '13 at 00:03
  • 1
    Have you tested your option with a modern SQL-based option to show that it won't work well with large #s of users? How many users? What do you expect the working set to be when the comparison runs? – WiredPrairie Apr 30 '13 at 00:07
  • Indeed I have tested it on SQL Server. I'm talking about at least a million of users to begin. It starts choking (by choking I mean take more than 10 seconds to run, which is unacceptable) with a 10000 users already. 10000 is nothing for SQL, but remember, that is times say a 100 questions, times say 5 answers per question to run through. – Dmitry Efimenko Apr 30 '13 at 00:40
  • Of course it chokes, stored procedures are good at atomicity within a transactional state, you are looking to make something scale which was never designed to scale `:/` If you are seeking this behaviour to be run regularly you might need to rethink your design descisions in both NoSQL and SQL alike. Take a leap from SOs book here, they try and run things like this, at most, once a day and cache a lot of their content. They don't run this kind of stuff in realtime on the spot – Sammaye Apr 30 '13 at 07:25
  • SOs book? Didn't get that part. Is there a link I'm missing? – Dmitry Efimenko Apr 30 '13 at 09:37
  • (Stackoverflow = SO... They've done a lot of posts over the years about their architecture.) I'm not sure why you accepted the answer from Lucia? I certainly wouldn't recommend that for your needs. http://docs.mongodb.org/manual/reference/command/eval/#dbcmd.eval – WiredPrairie Apr 30 '13 at 10:45
  • well, he did answer if it's possible to run a procedure equivalent in MongoDB. And in the comments I found out that MongoDB is not the tool for me. The question didn't ask which DB should I chose (and it should have...) – Dmitry Efimenko Apr 30 '13 at 16:58
  • @Sammaye, WiredPrairie, guys, would anyone of you be able to give me a link to a resource that you think describes architecture that I should be using? Though I'm not sure if SO's architecture would be helpful since they don't seem to do the kind of data processing I'm looking for. – Dmitry Efimenko Apr 30 '13 at 20:49

1 Answers1

3

Take a look at MongoDB Stored Procedure Equivalent. In general you should be able to do these things with javascript.

Community
  • 1
  • 1
Lucia Pasarin
  • 2,268
  • 1
  • 21
  • 37
  • 1
    These are not stored procedures, also they are not good practice – Sammaye Apr 29 '13 at 20:14
  • You are right. http://docs.mongodb.org/manual/tutorial/store-javascript-function-on-server/ At least I never did it :) – Lucia Pasarin Apr 29 '13 at 20:34
  • I guess then MongoDB is not the right tool for the job. Any recommendations on other NoSql databases? – Dmitry Efimenko Apr 29 '13 at 20:55
  • why does it have to be specifically a stored procedure? – Asya Kamsky Apr 30 '13 at 03:19
  • 1
    what else can it be? It needs to be a process of some sort that is triggered by the web application's server side code. This process needs to completely run in the database. This quite well describes a stored procedure – Dmitry Efimenko Apr 30 '13 at 18:17
  • stored procedures are used for possible future changes in application level. if you write queries at application level, and if you change your application, you have to re-implement queries again. Stored procedures saves you in this case. – hakan Oct 22 '13 at 14:38