atlas.find在本地mongodb正常工作时返回空数组

a11xaf1n  于 2023-08-04  发布在  Go
关注(0)|答案(2)|浏览(75)

无错误控制台日志[]

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"本地主机uri工作正常
我已经确保我没有拼错我的PlayersV3集合
任何能给我指出正确方向的东西

dz6r00yl

dz6r00yl1#

试着使用这个URI,假设你的数据库名是“nhl”,并在URI中添加你的atlas用户名和密码。
语法:

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

字符串
示例:

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

watbbzwu

watbbzwu2#

第一个月
通过添加数据库名称作为查询参数之一,修复了该问题

相关问题