The Journey of #100DaysOfCode (@henna_dev)

#Day71 of #100DaysOfCode

Today the loooonnng weekend ended :frowning: so it was a little stressful day, thinking of all the work I have ahead of me :stuck_out_tongue: Today I spent time working on multiple things, Realm, MongoDB, and my Node.js message-mixer app to learn module exports and require functions.

On MongoDB front, I wanted to understand how to define JSON schema but I was not able to figure that out, so I had to enable development mode On for my realm app, add a new class to my application and then sync to Atlas and that will auto-generate the schema on cloud. I am working on Restaurant App using Atlas Sync .

POJO class:

open class Borough (
    @PrimaryKey
    var _id: ObjectId = ObjectId(),

    var borough: String? = null,

    var _partition: String = "borough"
): RealmObject() {
}

MongoDB Schema generated on Cloud

{
  "title": "Borough",
  "bsonType": "object",
  "required": [
    "_id",
    "_partition"
  ],
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "borough": {
      "bsonType": "string"
    },
    "_partition": {
      "bsonType": "string"
    }
  }
}

I also learned I cannot run distinct query from MongoDB Compass but I can execute it on mongo shell. Another thing I learned was the connection to shell does not happen with any other database than test . For this I think I will have to ask the expert :smiley:

MongoDB shell version v4.4.1
Enter password: 
connecting to: mongodb://**<truncated>**.mongodb.net:27017, **<truncated>**.mongodb.net:27017, **<truncated>**.mongodb.net:27017/database?authSource=admin&compressors=disabled&gssapiServiceName=**<truncated>**
{"t":{"$date":"2022-04-18T15:08:07.345Z"},"s":"I",  **<truncated>**,
"msg":"RSM host selection timeout",
"error":"FailedToSatisfyReadPreference: Could not find host matching read preference { mode: \"nearest\" } for set atlas-nudr3h-shard-0"}}


*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.

Error: connect failed to replica set **<truncated>**
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1

I found distinct boroughs and made a separate collection for them in the restaurant database

db.restaurants.distinct("borough")
[
	"Bronx",
	"Brooklyn",
	"Manhattan",
	"Missing",
	"Queens",
	"Staten Island"
]

db.Borough.insertMany([{borough:"Bronx"},{borough:"Brooklyn"},{borough:"Manhattan"}])

db.Borough.find({})
{ "_id" : ObjectId("625d9151be17483a1e2ac403"), "borough" : "Bronx" }
{ "_id" : ObjectId("625d9151be17483a1e2ac404"), "borough" : "Brooklyn" }
{ "_id" : ObjectId("625d9151be17483a1e2ac405"), "borough" : "Manhattan" }
{ "_id" : ObjectId("625d91b4be17483a1e2ac406"), "borough" : "Missing" }
{ "_id" : ObjectId("625d91b4be17483a1e2ac407"), "borough" : "Queens" }
{ "_id" : ObjectId("625d91b4be17483a1e2ac408"), "borough" : "Staten Island" }


On the node js front, I managed to find the error that I was facing with the module.exports. I had to type this dot function name to refer it than calling it without the keyword.

Also, the stack overflow answer helped me figure out, I am calling the function incorrectly.

I added the challenge code to Github as it was an interesting Encryption challenge :smiley:

Until tomorrow :wave:

3 Likes