Using findOne in a loop takes too long in Node.js

后端 未结 5 483
时光取名叫无心
时光取名叫无心 2020-12-12 07:35

I\'m using Node.js with MongoDB, I\'m also using Monk for db access. I have the below code :

console.time(\"start\");

collection.findOne({name: \"jason\"},         


        
5条回答
  •  醉梦人生
    2020-12-12 08:31

    collection.aggregate([
                                    {
                                        $match:{
                                            id :{ "$in" : document.friends},
                                        }
                                    }
                                    ]).exec(function ( e, d ) {
                                        console.log( d )            
    
                                        if(!e){
                                            // your code when got data successfully
                                        }else{
                                            // your code when you got the error
                                        }    
                                    });
    

提交回复
热议问题