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 8664171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:10:43+00:00 2026-06-12T17:10:43+00:00

I would like to populate my mongo with some test data. I have defined

  • 0

I would like to populate my mongo with some test data.

I have defined mongoose models and I was wandering if it was possible to pragmatically create mongo documents using pre defined models.

For example, model Items

var Schema = mongoose.Schema;

var Items = new Schema({
    title:      { type: String, required: true },
    desc:       { type: String}
});
  • 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-12T17:10:45+00:00Added an answer on June 12, 2026 at 5:10 pm

    Sure, do it in a single-purpose node app. Create a new app that doesn’t use express or whatever web framework, but instead just has your model definition and a connection to your database.

    You’ll need a data source of course for the test data, which you could just use a random word generator, like this one: http://james.padolsey.com/javascript/random-word-generator/

    function createRandomWord(length) {
        var consonants = 'bcdfghjklmnpqrstvwxyz',
            vowels = 'aeiou',
            rand = function(limit) {
                return Math.floor(Math.random()*limit);
            },
            i, word='', length = parseInt(length,10),
            consonants = consonants.split(''),
            vowels = vowels.split('');
        for (i=0;i<length/2;i++) {
            var randConsonant = consonants[rand(consonants.length)],
                randVowel = vowels[rand(vowels.length)];
            word += (i===0) ? randConsonant.toUpperCase() : randConsonant;
            word += i*2<length-1 ? randVowel : '';
        }
        return word;
    }
    

    Then you’d need to populate the database like this:

    var numTestDocs = 100; // or however many you want
    for(var i = 0; i < numTestDocs; i++) {
       var someLength = 12; // Alternatively, you could use a random number generator
       var randomWord = createRandomWord(someLength);
       var item = new Item ({
          title : randomWord ,
          desc  : randomWord + ' is just a test'
       });
       item.save(function(err, doc) {
          // do error handling if you want to
          console.log('Test Record Saved with id: ' + doc._id);
       });
    }
    

    Then just run that node app.

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

Sidebar

Related Questions

I have a view that I would like to populate data when the next
I have a MySQL database which contains data i would like to populate into
I have an (access) database table which contains data I would like to populate
I have a empty table that I would like to populate based on data
I have two divs. I would like to move/populate the text from div id
I would like to know how do I populate a TableView with data... All
I have a typed dataset in my project. I would like to populate a
I would like to populate the data store. Yet all the examples and instructions
I have a continuous form that i would like to populate via a sql
I have a GUI created in Glade, and I would like to populate the

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.