Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8446507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:57:13+00:00 2026-06-10T09:57:13+00:00

I have a collection of Posts and Users where users can upvote/downvote each post.

  • 0

I have a collection of Posts and Users where users can upvote/downvote each post. What would be the best way to store this in a mongodb database to make sure that users cannot vote for a given document more than once?

The simplest nosql-ish solution I came up with is storing an array of user_ids who voted inside each Post document (or even array of (user_id, vote) where vote is +1 or -1 so that users will be able to change their vote). Is it a good idea from the performance standpoint given that each post can have thousands of votes?

What about really popular websites like Reddit where top posts can have hundreds of thousands of votes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:57:14+00:00Added an answer on June 10, 2026 at 9:57 am

    MongoDB documents are currently restricted to a maximum of 16MB, so assuming Gilbert’s calculations are accurate, you wouldn’t be able to store all 6 Million user_ids in the Post document.

    However, you could consider storing the votes in the User document instead (i.e. the post_ids that the particular user voted for). It is much less likely that a user votes on 6 million different posts, so this way you won’t reach the size limit as quickly.

    Another way to handle this: If you expect that many votes for a particular post, you may want to store the votes outside the Post documents in a separate collection and do an additional query, similar to a many-to-many JOIN table in SQL fashion:

    user_votes { user_id: ObjectId(...), post_id: ObjectId(...), vote:-1 }
    

    and create a compound index on (user_id, post_id).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection of posts created by separate users in my database. Each
A user can have many posts, and each post can have many comments. When
I have Collection List<Car> . How to compare each item from this collection with
This post is an continuation of this post I have DlUser Class each object
I have a document structure in MongoDB like this: User |---> Posts |----> Comments
I have a collection of Post objects and I want to be able to
I have the following code: // // POST: /PlayRoundHole/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection collection)
I'm planning to have collection of items stored in a TCollection. Each item will
I have a collection that use as a cache. How can I limit the
I have a question on designing index in MongoDB. Say i have a users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.