0

I have a mongodb database server.I want to get it fill up with large number of entries in a particular collection let say a collection named "user". I want to know if there would be a script for saving large no of randomly created entries in my mongodb database from linux terminal or a Java code for the same. I have a script that creates 10,000 entries in "user" collection:

> for(i=0;i<10000;i++){db.user.insert({username:'ashok'+i,password:'123'});}

This query creates the user names as ashok1 , ashok2 ,.... I want a script that could create random user names. It could be better if I could get this done in grails.

  • Why don't you generate a random string using alphabets and use that as username? – Buchi Feb 28 '13 at 22:20
  • You could use [this](http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript) and make a script that runs on mongodb. – Miguel Cartagena Apr 04 '13 at 18:55
  • I solved my problem using this code for grails User user = new User(username: createRandomString() , password: createRandomString() , dateCreated:date) /** *It will create random string of length between 6 to 12 charaters */ def createRandomString() { String charset = (('A'..'Z') + ('a'..'z') + ('0'..'9')).join() int length = 6 + new Random().nextInt(7) String randomString = RandomStringUtils.random(length, charset.toCharArray()) return randomString } – user2060968 Aug 22 '13 at 10:23

0 Answers0