mongoose.find dosen't work

19 views
Skip to first unread message

Sven-Meikel Auer

unread,
Aug 30, 2015, 6:03:45 PM8/30/15
to Mongoose Node.JS ODM
When I query the following it returns: {"suppliers":[]}
But it must return all suppliers that contains this smaId. Please help me.

router.get('/:supplierId', function(req, res) {
  Suppliers = conn.model('Suppliers')
  Suppliers.find({ "smaId": req.params.supplierId }, function(err, supplier) {
     if (err) {
       return res.sendStatus(500)
     }
     if (!supplier) {
       return res.sendStatus(404)
     }
    res.send({ suppliers: supplier })
  })
})

THE SCHEMA

  , Schema = require('mongoose').Schema

  var suppliersSchema = new Schema(
    { smaId: String
    , companyName: String
    , companyNametwo: String
    , street: String
    , city: String
    , zipCode: String
    , country: String
    , telefon: String
    , telefax: String
    , emailadress: String
    , erstkontaktemail: String
    , lieferungenan: String
    , website: String
    , cat: String
  },
    { collection : 'suppliers' }
)

Sven-Meikel Auer

unread,
Aug 30, 2015, 6:11:19 PM8/30/15
to Mongoose Node.JS ODM
When I made following get I all records. But what it the fail by me find query with smaId?

  Suppliers = conn.model('Suppliers')
  Suppliers.find({}, function(err, supplier) {
    if (err) {
      return res.sendStatus(500)
    }
    if (!supplier) {
      return res.sendStatus(404)
    }
    res.send({ suppliers: supplier })
  })
  })

Please help me. Greetings Sven

sm_a

unread,
Aug 31, 2015, 1:46:05 PM8/31/15
to Mongoose Node.JS ODM
I have it made. I need no answer to my question.

Greetings
Sven
Reply all
Reply to author
Forward
0 new messages