mongoose can't always get data
mongoose.connect(myurl, { useNewUrlParser: true, useUnifiedTopology: true }, (err) => {
if (err) {
console.log('isok');
} else {
console.log("err")
}
});
const commonChema = new mongoose.Schema();
const navsDB = mongoose.model('navsdb', commonChema, 'navsdb');
navsDB.find().then(e => {
console.log(e);
})
// run 10 times // [] [] [havedata] [] [havedata] [havedata] [] []
// can't always get data
or
const navsDB = mongoose.model('navsdb', mongoose.Schema({
username: String,
password: String,
email: String,
phone: String,
qq: String
}, { collection: 'navsdb' }));
navsDB.find().then(e => {
console.log(e);
})
// run 10 times // [] [] [havedata] [] [havedata] [havedata] [] []
// can't always get data
Can not reproduce. Please follow the issue template.
@AbdelrahmanHafez I have re-edited
I need help, can anyone help me
What version of Mongoose and MongoDB? Also, is the data within the collection changing in between when you're running your script?
@vkarpov15 First of all, I'm a bit busy these days! my package.json Mongoose:v5.8.1 mongodb:3.3.5 my My mongodb client:V4.2 When I run the script, sometimes there is data, sometimes there is no data
navsDB.find().then(e => {
console.log(e);
// Run 10 times log [empty] [] [] [havaData] [havaData] [] ````
// Randomly return data
})
@vkarpov15 package.json > mongodb:3.4.1 run 6 time test
[nodemon] restarting due to changes...
[nodemon] starting node index.js
Example app listening at http://:::3001
[]
[nodemon] restarting due to changes...
[nodemon] starting node index.js
Example app listening at http://:::3001
[ { _id: 5df058118342d275a1864314, date: '2019-12-27 test' } ]
[nodemon] restarting due to changes...
[nodemon] starting node index.js
Example app listening at http://:::3001
[ { _id: 5df058118342d275a1864314, date: '2019-12-27 test' } ]
[nodemon] restarting due to changes...
[nodemon] starting node index.js
Example app listening at http://:::3001
[]
[nodemon] restarting due to changes...
[nodemon] starting node index.js
Example app listening at http://:::3001
[ { _id: 5df058118342d275a1864314, date: '2019-12-27 test' } ]
[nodemon] restarting due to changes...
[nodemon] starting node index.js
Example app listening at http://:::3001
[ { _id: 5df058118342d275a1864314, date: '2019-12-27 test' } ]
[nodemon] restarting due to changes...
[nodemon] starting node index.js
Example app listening at http://:::3001
[]
Is there anything else connecting to that database?