I am building an app which allows users to do some "tasks" to earn points. The "tasks" are part of a "campaign" which themselves are a part of "brands". I am confused about the schema for storing the response of the users. This is what i have built. All tasks have some activities which a user needs to complete to complete the task.

{ _id : ObjectId,
  user_id : ObjectId,
  campaign : [ 
        { _id : ObjectId,
          campaign_id : ObjectId,
          brand_id : ObjectId,
          completed : Boolean,
          points : Number,
          tasks : [
             { _id : ObjectId,
               task_id : ObjectId,
               start_time : Date,
               rewards : points,
               responses : [
                     { _id : ObjectId,
                       activity_id : ObjectId,
                       response : Mixed, 

1. inserting new response and updating how many no. of people doing the campaign of the given task.
2. getting completed tasks and respective rewards of a user.
3. getting completed campaigns of a user.
4. updating a user's response to a task.
5. finding unique responses by all users for a given activity.

Problems :
1.The problem is that this schema contains nested arrays and mongodb doesnt allow me to use positional operators after level 1.

It would be helpful if someone can suggest a design which can perform these queries in a better way.

  • You would help yourself by posting on stackoverflow.com instead and specifying your true "use case" for your desired functionality. NoSQL implies that decisions like this are not in the traditional "DBA" role as with SQL backends. Also the "use case" really matters since in "NoSQL" there are usually "other ways to handle this" than your traditional line of thinking might allow. – Neil Lunn Feb 26 '15 at 10:11
  • @NeilLunn, thanks for the suggestion. I did that already :) and got a good response. – Akshat Feb 27 '15 at 9:27

Your Answer

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

Browse other questions tagged or ask your own question.