Skip to content

Commit ec6c591

Browse files
committed
Add users to mongodb
1 parent 1b3dac6 commit ec6c591

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

.github/workflows/playwright.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ jobs:
2323
java-version: 21
2424
distribution: 'temurin'
2525
cache: 'maven'
26-
- name: Load users.json to MongoDB
26+
- name: Install mongosh and import start data in database
2727
run: |
28-
mongoimport \
29-
--host localhost \
30-
--port 27017 \
31-
--db myconext \
32-
--collection users \
33-
--file myconext-server/src/test/resources/users.json \
34-
--jsonArray
28+
sudo apt-get install gnupg
29+
wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-7.0.asc
30+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
31+
sudo apt-get update
32+
sudo apt-get install -y mongodb-mongosh
33+
mongosh --version
34+
mongosh localhost:27017/myconext playwright/loadusers.js
3535
- name: Set up cache
3636
uses: actions/cache@v4
3737
with:

playwright/loadusers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const filePath = "../myconext-server/src/test/resources/users.json";
2+
3+
try {
4+
const fileContent = fs.readFileSync(filePath, 'utf8');
5+
const users = JSON.parse(fileContent);
6+
const result = db.users.insertMany(users);
7+
8+
print(`Successfully inserted ${result.insertedCount} documents into the 'users' collection.`);
9+
} catch (e) {
10+
print(`Error loading or inserting data: ${e.message}`);
11+
}

0 commit comments

Comments
 (0)