Alice
Alice

Reputation: 1401

Where to load bulk data in the MEAN+Mongoose stack?

In which of the MEAN stack level is it best to load bulk data? I have about 200 - 800 entries of 2 - 3 different types (i.e. they would require 2 - 3 different Mongoose schemas).

Here are the options to load these data (feel free to point out any misunderstandings, I'm new):

  1. Client side: Angular level
    • Automate lots of user inputs
  2. Server side: Nodejs + Express + Mongoose
    • Define the schema in Mongoose, create the objects, save each one
  3. Database side: Mongodb
    • Make a json file with the data, and import it directly into Mongo:
      mongoimport -d db_name -c collection_name --jsonArray --file jsonfilename.json

The third way is the purest and perhaps fastest, but I don't know if it's good to do it at a such low level.

Which one is the best? If there is not an optimal choice, what would be the advantages and disadvantages of each?

Upvotes: 3

Views: 2311

Answers (2)

saintedlama
saintedlama

Reputation: 6898

It depends on what you're bulk loading and if you require validations to be done.

  1. Client side: Angular level
    • If you require the user to do the bulk loading and require some human readable error messages that's your choice
  2. Server side: Nodejs + Express + Mongoose
    • You can bulk import from a file
    • Expose a REST endpoint to trigger bulk import of your data
    • You can use Mongoose for validation (see validation in mongoose)
    • Mongoose supports creating multiple documents with one call (see Model.create)
  3. Database side: Mongodb
    • Fast, No code needed
    • No flexible validation

I'd choose the option that fits your understanding of the bulk data import best: If it requires a UI your option is 1 combined with 2, if you see this as part of your "business" logic and you're importing data from a external file or want other systems to trigger that import your option is 2, if you see it as a one time action to import data or you don't require any validation or logic related to the import the best choice is option 3.

Upvotes: 5

Bulkan
Bulkan

Reputation: 2592

Loading it via the client side will require you to write more code to handle importing and to send to the backend, then handle it in Node.js.

The fastest method out of all of them would be to directly import it the data using mongoimport.

Upvotes: 0

Related Questions