A
A
Anton Ulanov2016-02-27 19:53:06
MongoDB
Anton Ulanov, 2016-02-27 19:53:06

Where did I go wrong in node.js?

Good time of the day. Strongly do not kick :) I can not understand where I made a mistake. I have a mongo schema

module.exports = function() {
  var LocationObject = new Schema({
    user_id: String,
    loc: {type: {type: String},coordinates: []},
    timestamp: String,
    hdop: String,
    altitude: String,
    speed: String
  });
  // define the index
  LocationObject.index({loc: '2dsphere'});

  mongoose.model('Location', LocationObject);
};

there is a route
router.get('/gps/loc*', function(req, res) {
  var data = [
    user_id = req.params.user_id,
    lat = req.params.lat,
    lon = req.params.lon,
    timestamp = req.params.timestamp,
    hdop = req.params.hdop,
    altitude = req.params.altitude,
    speed = req.params.speed
  ];

  async.each(data, function(item, cb) {
    Location.create(item, cb);
    console.log(data);
  }, function(err) {
    if (err) {
      throw err;
    }
  });
});

I can’t write the transmitted data to the database in any way
. Plz tell me where to fix it and why exactly there. I don't want to ask stupid questions later :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question