skip to Main Content

no errors console logs []

const mongoose = require('mongoose'); 

const uri = "mongodb+srv://:@cluster0.yhy4bwu.mongodb.net/?retryWrites=true&w=majority";

const playerSchema = new mongoose.Schema({
    fullname: String,
    goals: Number,
    assists: Number, 
    gamesPlayed: String,
    shots: Number, 
    positionCode: String, 
    plusminus: String, 
    team: String, 
    timeOnIcePerGame: Number, 
    espnId: Number
})


mongoose.connect(uri)
    .then(async ()=>{
        model = mongoose.model('PlayersV3', playerSchema, 'PlayersV3')

        const doc = await model.find({fullname : {$regex :  new RegExp('a', "i")}}).limit(15).sort({goals: -1});
        console.log(doc)
    }).catch((error)=>{
        console.log(error)
    });

const local_uri = "mongodb://127.0.0.1:27017/nhl" the localhost uri works

I have made sure that I have not misspelled my PlayersV3 collection

anything that would point me in the right direction helps

2

Answers


  1. Chosen as BEST ANSWER

    const uri = "mongodb+srv://:@cluster0.yhy4bwu.mongodb.net/Databasename?retryWrites=true&w=majority";

    fixed it by adding in the database name as one of the query parameters


  2. try using this one uri
    assuming that your db name is "nhl" and also add you atlas username and password in uri.

    syntax:

    "mongodb+srv://<atlas username>:<password>@cluster0.yhy4bwu.mongodb.net/<database name>?retryWrites=true&w=majority";
    

    example:

     const uri = "mongodb+srv://<atlas username>:<password>@cluster0.yhy4bwu.mongodb.net/nhl?retryWrites=true&w=majority";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search