Wednesday 15 July 2015

node.js - No blocking operation in MongoJS -


I have to do an operation that calculates something for me, but I can not use the result because I Always staying in a waiting state, in fact my program lives in my terminal until I enter ctrl + c

For my program I have the key in nodes, where I use my results module.

  var myJSONClient = {"nombre": "& lt; nombre_cliente"; "," interval ": [0,0]}; Vir Intervalo = Gestinar Thattenation (MySocialClient, Vector_Interval); Console.log ("int" + interval); // return undefined   

and this module is

  var gestion = function (myJSON, vector_intervalo) {var dburl = 'localhost / mongoapp'; Var Collection = ['Clients']; Var requires DB = ('demand'). Connect (Debert, Collection); Var interval_final; Function client (nombre, intervalo) {this.nombre = nombre; This.intervalo = interval; } Var Client1 = New Customers (myJSON.nombre, myJSON.intervalo); Db.clientes.save (client11, function (err, savecliente) {if (err!! Savecliente) console.log ("client" + client11.nombre + "is not saved Error:" + err); else console.log ("Customer" + saveCliente.nombre + "saved"); Interval_final = count (vector_intevalo); console.log (interval_final); // Here I can see the correct contents of the variable interval_final;) ​​console.log (intervalo_final) ; // This return Interval_final is not executed;} Export.gestion = gestion;    

< P> Welcome to the async world! :)

First of all, you are not In the node, the networking is completely asynchronous.

In which part you call console.log , the job Because callback function of db.clientes.save call this callback tells you that your Mongo save is left.

What does Asynchronous networking mean? / Strong>
This means your saved will be processed in the future. The script will not wait for the response to continue the code. console.log will be immediately saved and executed immediately after the call as it is done.

For the "wait status" of your script, it never ends, you should take a look at. The answer is.

No comments:

Post a Comment