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

  • Home
  • SEARCH
  • 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 6973795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:09:16+00:00 2026-05-27T17:09:16+00:00

I have a mongoDB collection with an array field that represents the lists the

  • 0

I have a mongoDB collection with an array field that represents the lists the user is member of.

user { 
  screen_name: string
  listed_in: ['list1', 'list2', 'list3', ...] //Could be more than 10000 elements (I'm aware of the BSON 16MB limits)
}

I am using the *listed_in* field to get the members list

db.user.find({'listed_in': 'list2'});

I also need to query for a specific user and know if he is member of certain lists

var user1 = db.findOne({'screen_name': 'user1'});

In this case I will get the *listed_in* field with all its members.

My question is:
Is there a way to pre-compute custom fields in mongoDB?
I would need to be able to get fields like these, user1.isInList1, user1.isInList2

Right now I have to do it in the client side by iterating through the *listed_in* array to know if the user is member of “list1” but *listed_in* could have thousand elements.

  • 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-05-27T17:09:17+00:00Added an answer on May 27, 2026 at 5:09 pm

    My question is: Is there a way to pre-compute custom fields in mongoDB?

    Not really. MongoDB does not have any notion of “computed columns”. So the query you’re looking for doesn’t exist.

    Right now I have to do it in the client side by iterating through the *listed_in* array to know if the user is member of “list1” but *listed_in* could have thousand elements

    In your case you’re basically trying to push a client-side for loop onto the server. However, some process still has to do the for loop. And frankly, looping through 10k items is not really that much work for either client or server.

    The only real savings here is preventing extra data on the network.

    If you really want to save that network traffic, you will need to restructure your data model. This re-structure will likely involve two queries to read and write, but less data over the wire. But that’s the trade-off.

    • 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 articles in MongoDB that has the following structure: {
I have a MongoDB Collection called Questions which holds JSON Objects that look like
I have MongoDB.BsonDocument, i want to convert that BsonDocument to List of collection, how
I'm learning mongodb and rails right now... I have two collection, User and Event
I'm trying to use mongodb with PHP. For that, I have created a MongoHQ
I have a class Document (in a mongodb collection) and persist various sub classes
I have a collection in MongoDB with 20 million documents and an index created
I have a MongoDB collection and need to find the max() value of a
I need to have collections such as: client1.users client1.images client2.users client2.images MongoDB supports Collection
I'm running MongoDB on Windows. I have 1 or more threads that drop and

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.