无错误控制台日志[]
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集合
任何能给我指出正确方向的东西
2条答案
按热度按时间dz6r00yl1#
试着使用这个URI,假设你的数据库名是“nhl”,并在URI中添加你的atlas用户名和密码。
语法:
字符串
示例:
型
watbbzwu2#
第一个月
通过添加数据库名称作为查询参数之一,修复了该问题