Which would be the best or most recommended way to connect to MongoDB?

Hello, I would like to ask a question to the community about MongoDB and Meteor.

On the last releases I have seen multiple changes in MongoDB drivers or the embedded mongo and I wanted to know which package/inbuilt feature is the most used or common way the Meteor projects tend to have when talking about MongoDB connections, schemas, etc…

Right now I’m using mongoose to do all this stuff of Mongo connections and fetching of table data.

On another side, I have a small problem that maybe you can explain me why, my application has a lot of users and when I run the line Meteor.users.find().fetch() it takes a long time to load, someone knows why?

I have to investigate more about the server side of Meteor, but I wanted to ask all of you and see what you think.

Thank you so much, willing to see your responses!!

  1. How long is “long time?”
  2. How many users are we talking about?

Why would you run this without any filters or limits? Let’s say you have 5000 users you will never show them on a single page right?

In general most queries have filtering, limiting or both because the user cannot deal with too much data as a human.

Also important if there a bigger objects is to limit the amount of data with the fields option. That is for example really useful in publications. Security | Meteor Guide

1 Like

You are right I should only request the data that I need using the fields options, I needed the full list of users for the case of:
I want to give users access to a tab and I need all the users that do not have access already so I can select them inside a dropdown but I could change the code to display users when searching by words or something like that.

  • My current number of users is about 5,042 users.
  • About the time to get them all we are talking around 43 seconds

A thing that I found out a time ago trying to optimise the code is that I can only make a connection to the MongoDB at a time, if I have 5 connections in the same page, the second one has to wait for the first one to finish in order to start and fetch the data of the table, I don’t know if you know a solution or workaround for this. Is it possible to make connections in parallel?


Yes that is the right solution, something like this: https://react-select.com limit the results to max 50 for example and it’s quick.

Do you mean subscriptions?

What do you use? React/Blaze or something else?

Can you show some demo code / examples on how you do it?