Mongodb operation for help!

  node.js, question
db_handle = new mongodb.Db("spa", mongodb_server, {safe: true});
 function(outer_error, collection){
 collection.find(find_map, fields_map).toArray(function(inner_error, map_list){

Why does the above operation need to be operated in the collection method? It seems to be wrapped in two layers, which is a bit confusing

The essence of NodeJS lies in asynchronous non-blocking, and many things will be easy to understand if you understand this. To put it bluntly, there will be a function where you need to wait, and this function will be called when the operation is ready. So the two functions you have here actually represent two waits:

  1. Connect to the database. This is the network operation needs to wait, so the first function is waiting for this

  2. Get results. Your query will take some time to return, so the second function is waiting for the result to return.