Hi Community,
I am struck at a situation where I’m unable to go trough using mongo DB with node js.
My configuration version;
- Node.js: v18.16.0
- MongoDB: 6.0.6
3.Mongosh: 1.9.0 - I have windows 10 with x64 machine
Now, I have done all the steps from;
- Installling latest version, as can be seen above.
2.configuring environmental variables - Creating C:/data/db
- Using 127.0.0.1 instead of localhost
However, when working with following lines of code, I do following steps;
- Run mongod, in new terminal
- Run mongosh, in new terminal
- Run node app.js, new terminal
“node app.js” doesn’t givve any results and keeps on as it is.
Please help me here, I’m stuck here for 2 days straight without sleep, also I’m following a bootcamp where she made us create a .bash_profile which contained following lines but as of now I removed (didn’t work when present also);
alias mongod=“/c/Program\ files/MongoDB/6.0/bin/mongod.exe”
alias mongo=“/c/Program\ Files/MongoDB/6.0/bin/mongo.exe”
Also, refer to the code below and let me know my issue or bunder.
</>
const mongoose = require (‘mongoose’);
mongoose.connect(‘mongodb://127.0.0.1:27017/fruitsDB’, {useNewUrlParser: true, useUnifiedTopology: true});
const furitSchema = new mongoose.Schema({
name: String,
rating: Number,
review: String
});
const Fruit = mongoose.model(“Fruit”,furitSchema);
const fruit = new Fruit({
name:“Apple”,
rating: 7,
review:“Pretty solid”
});
fruit.save();
const findDocuments = function(db, callback) {
// Get the documents collection
const collection = db.collection('fruits');
// Find some documents
collection.find({}).toArray(function(err, fruits) {
assert.equal(err, null);
console.log("Found the following records");
console.log(fruits)
callback(fruits);
});
};
</>