Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
M
MongoDB Cluster With Sharding and Replication
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rawan.salameh
MongoDB Cluster With Sharding and Replication
Commits
92d177ad
Commit
92d177ad
authored
Apr 20, 2026
by
rawan.salameh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit: MongoDB Cluster with Sharding and Replication
parent
6cb5b187
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
80 additions
and
2 deletions
+80
-2
MoviesGenerator.java
src/main/java/MoviesGenerator.java
+2
-2
UsersGenerator.java
src/main/java/UsersGenerator.java
+66
-0
MoviesGenerator.class
target/classes/MoviesGenerator.class
+0
-0
UsersGenerator.class
target/classes/UsersGenerator.class
+0
-0
log4j.properties
target/classes/log4j.properties
+7
-0
insert-many-movies-1.0-SNAPSHOT-jar-with-dependencies.jar
...insert-many-movies-1.0-SNAPSHOT-jar-with-dependencies.jar
+0
-0
insert-many-movies-1.0-SNAPSHOT.jar
target/insert-many-movies-1.0-SNAPSHOT.jar
+0
-0
pom.properties
target/maven-archiver/pom.properties
+3
-0
createdFiles.lst
...-compiler-plugin/compile/default-compile/createdFiles.lst
+1
-0
inputFiles.lst
...en-compiler-plugin/compile/default-compile/inputFiles.lst
+1
-0
No files found.
src/main/java/MoviesGenerator.java
View file @
92d177ad
...
...
@@ -12,8 +12,8 @@ import java.util.Random;
public
class
MoviesGenerator
{
//router address
private
static
final
String
MONGO_DB_URL
=
"mongodb://1
72.29.3.101
:27033/"
;
private
static
final
String
DB_NAME
=
"
videodb
"
;
private
static
final
String
MONGO_DB_URL
=
"mongodb://1
92.168.52.128
:27033/"
;
private
static
final
String
DB_NAME
=
"
MoviesDB
"
;
private
static
final
String
COLLECTION_NAME
=
"movies"
;
private
static
final
Random
random
=
new
Random
();
...
...
src/main/java/UsersGenerator.java
0 → 100644
View file @
92d177ad
import
com.mongodb.client.MongoClient
;
import
com.mongodb.client.MongoClients
;
import
com.mongodb.client.MongoCollection
;
import
com.mongodb.client.MongoDatabase
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
org.bson.Document
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Random
;
public
class
UsersGenerator
{
private
static
final
String
MONGO_DB_URL
=
"mongodb://192.168.52.128:27033/"
;
private
static
final
String
DB_NAME
=
"MoviesDB"
;
private
static
final
String
COLLECTION_NAME
=
"users"
;
private
static
final
Random
random
=
new
Random
();
private
static
final
String
[]
MOVIE_POOL
=
{
"Inside out"
,
"Aladdin"
,
"Avatar"
,
"Inception"
,
"Interstellar"
,
"Matrix"
,
"Up"
,
"Soul"
};
public
static
void
main
(
String
[]
args
)
{
try
(
MongoClient
mongoClient
=
MongoClients
.
create
(
MONGO_DB_URL
))
{
MongoDatabase
database
=
mongoClient
.
getDatabase
(
DB_NAME
);
generateUsers
(
5000
,
database
,
COLLECTION_NAME
);
}
}
private
static
void
generateUsers
(
int
numberOfUsers
,
MongoDatabase
database
,
String
collectionName
)
{
MongoCollection
<
Document
>
collection
=
database
.
getCollection
(
collectionName
);
collection
.
deleteMany
(
new
Document
());
List
<
Document
>
documents
=
new
ArrayList
<>();
System
.
out
.
println
(
"Generating "
+
numberOfUsers
+
" users..."
);
for
(
int
i
=
0
;
i
<
numberOfUsers
;
i
++)
{
Document
user
=
new
Document
();
user
.
append
(
"user_name"
,
generateRandomName
())
.
append
(
"watched_movies"
,
generateWatchedMovies
())
.
append
(
"subscription_month"
,
random
.
nextInt
(
12
)
+
1
);
documents
.
add
(
user
);
if
(
documents
.
size
()
==
1000
)
{
collection
.
insertMany
(
documents
);
documents
.
clear
();
}
}
if
(!
documents
.
isEmpty
())
collection
.
insertMany
(
documents
);
System
.
out
.
println
(
"Finished generating users successfully!"
);
}
private
static
String
generateRandomName
()
{
return
RandomStringUtils
.
randomAlphabetic
(
5
,
8
);
}
private
static
List
<
String
>
generateWatchedMovies
()
{
int
count
=
random
.
nextInt
(
3
)
+
1
;
List
<
String
>
watched
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
watched
.
add
(
MOVIE_POOL
[
random
.
nextInt
(
MOVIE_POOL
.
length
)]);
}
return
watched
;
}
}
\ No newline at end of file
target/classes/MoviesGenerator.class
0 → 100644
View file @
92d177ad
File added
target/classes/UsersGenerator.class
0 → 100644
View file @
92d177ad
File added
target/classes/log4j.properties
0 → 100644
View file @
92d177ad
# Root logger option
log4j.rootLogger
=
ERROR, stdout
# Direct log messages to stdout
log4j.appender.stdout
=
org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target
=
System.out
log4j.appender.stdout.layout
=
org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern
=
%d{HH:mm:ss} %-5p %c{1}:%L - %m%n
target/insert-many-movies-1.0-SNAPSHOT-jar-with-dependencies.jar
0 → 100644
View file @
92d177ad
File added
target/insert-many-movies-1.0-SNAPSHOT.jar
0 → 100644
View file @
92d177ad
File added
target/maven-archiver/pom.properties
0 → 100644
View file @
92d177ad
artifactId
=
insert-many-movies
groupId
=
distributed.systems
version
=
1.0-SNAPSHOT
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
0 → 100644
View file @
92d177ad
MoviesGenerator.class
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
0 → 100644
View file @
92d177ad
D:\ADS\movies-generator-mongodb\src\main\java\MoviesGenerator.java
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment