3. Adding data to the database - B5-Recruiter-and-Employee/B5_Project GitHub Wiki
Our dummy data for MongoDB and Elasticsearch
For local environments, we prepared some fake data to insert into the database and elasticsearch. Important: This only adds candidates and job offers, but doesn't assign them a user.
-
Open two terminal tabs and run our app and Elasticsearch, if you haven't already.
-
(optional) Open MongoDB compass, connect with the current database
mongodb://localhost:27017/rem_matching_testand open a collection. In this example we use job_offers. -
(optional) Elasticsearch runs on
localhost:9200. Use this query to see the jobs in Elasticsearch:http://localhost:9200/job_offers/_search -
Seed data or delete everything by using the
seed.jsandclear_db.jsfiles. Open a third terminal tab and use these commands after navigating into the project folder:
node clear_db.js
node seed.js
The jobs are saved in MongoDB first and after that into Elasticsearch using the mongoosastic module.
- In case you had seeded the data to MongoDB and ES before, but need to seed it another time to update the dummy data in the database, the collections should be dropped in MongoDB either with commands or in MongoDB Compass by clicking on the collection name and selecting "Drop Collection" from the drop-down menu. Do not forget to delete the data from Elastic Search as well by running in the Console - Development tools - Kibana the delete command:
DELETE job_offers
Without deleting the previously seeded data in ES, user can have duplicates of data or errors.
-
If you want to connect a job offer profile to a user, you have to do it manually. For this, create a new user on the website or get the UserID of an existing one. (To connect job offers this must be a recruiter, and for candidate profiles it must be a candidate.)
-
Open MongoDBCompass and select the job offer. Paste the ID into the user field as ObjectId. It should look like this:
user: ObjectId("600d5ee5484a725e88c5a970")
Now do the same for your user. Get the ID of the job offer and insert it into the jobOffer array of the user. It should look like this:
jobOffers: Array
0: ObjectId("600d5ecc484a725e88c5a96a")
Additional tip:
if you get an unique key error while trying to insert new candidates: go to candidates collection on MongoCompass -> Indexes -> Drop the email index
Use Kibana
- To run Kibana, open a new terminal tab and cd to your Kibana installation folder. Run this command:
bin/kibana.bat
- To query all jobs in your database on Kibana, navigate to: Management -> Dev tools
- Enter this command:
GET jobs/_search - If you use queries to edit the data in Kibana, the changes won’t be saved into MongoDB.