File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments