Mongodb Atlas 404 error

Hi - I am new to learning NodeJS with mongodb. So please excuse and ask me if I didn’t provide enough information to look for help on this.

I am trying to connect with MongoDB Atlas using Nodejs, ExpressJS and mongoose schema.

The REST client in VS code that says 404 not found error and the connection: close

server.js code:

const express = require("express");
const app = express();
const port = 4000;

const mongoose = require("mongoose");

var uri = "mongodb+srv://";

 { useUnifiedTopology: true, useNewUrlParser: true }
 const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", function( ) {
    console.log("hurray! we connected");


const mongoose = require("mongoose");

const userTaskSchema = mongoose.Schema({
  taskTitle: {
    type: String,
    required: true,
  taskDescription: {
    type: String,
module.exports = mongoose.model("userTaskModel", userTaskSchema);

and when i start executing, server.js
it says
Hurray! we are connceted but REST client says 404 error . please help

Are you able to connect by shell using the connect string in your uri?

Thanks, I restarted the system, after that the DB got coneted to the server. not sure what went wrong before.

now I changed the DB connection as

var db = "mongodb://localhost:27017/example";

mongoose.connect(db, { useNewUrlParser: true, useUnifiedTopology: true });`

in shell,
when i use example
it switchd to that database

use collections is empty. why is that? the video tutorial that i followed for learning it says ther were collections created from mongoose chema. but all i see is empty in shell. why,please?

The uri you used earlier is different from what you used now

You are connecting to a mongodb on your local host
Please clarify which is the correct one

Did you meant show collections in the next line?
use collections means it will put you into collections DB
Have you created any collections under example?
If yes you should be able to see with show collections

Hi Ramachandra - Thanks for the help. I have completely changes my code to use localhost. Sorry for the confusion that it may caused.

I will create a new thread if I have question with relevant code.

It was my mistakee that in a hurry I typed
“Use collections” instead of “Show Collections” in the earlier post. very sorry.