mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

mongoose can't always get data

Open wangraoji opened this issue 6 years ago • 7 comments

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

wangraoji avatar Dec 17 '19 08:12 wangraoji

Can not reproduce. Please follow the issue template.

AbdelrahmanHafez avatar Dec 17 '19 17:12 AbdelrahmanHafez

@AbdelrahmanHafez I have re-edited

wangraoji avatar Dec 18 '19 01:12 wangraoji

I need help, can anyone help me

wangraoji avatar Dec 19 '19 02:12 wangraoji

What version of Mongoose and MongoDB? Also, is the data within the collection changing in between when you're running your script?

vkarpov15 avatar Dec 20 '19 19:12 vkarpov15

@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
 }) 

wangraoji avatar Dec 27 '19 03:12 wangraoji

@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 []

wangraoji avatar Dec 27 '19 03:12 wangraoji

Is there anything else connecting to that database?

vkarpov15 avatar Dec 30 '19 16:12 vkarpov15