L
L
lex2016-10-03 09:13:09
JavaScript
lex, 2016-10-03 09:13:09

How to use correctly?

Greetings!
Please tell me why the sli variable is not available when connecting to the database, I want to make records after receiving the promise. and going a little further, how can I then write an array like this in the base:
[
{ a : a} ,
]

service.get(current).then(sli => {
          var date = new Date();
          console.log(date);
          console.log(sli[0]);
          
          var MongoClient = require('mongodb').MongoClient, assert = require('assert');

          var url = 'mongodb://localhost:27017/test';
          // Use connect method to connect to the server
          MongoClient.connect(url, function(err, db, sli) {
            assert.equal(null, err);
            console.log("Connected successfully to mongoserver");
            console.log(sli);
            db.close();
          });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TekVanDo, 2016-10-03
bem @bemdev

Invisible because you override the sli variable in the callback:
And judging by the dock , the function has 2 parameters and not 3, so sli inside is undefined

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question