Mongo Returns full data while Mongoose does not return relative data
<p>When I use mongo Command Prompt to get data, it works fine:</p>

<p><a href="https://i.stack.imgur.com/kui8B.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kui8B.jpg" alt="enter image description here"></a></p>

<p>But when I do it using mongoose in node.js, I don't get referenced data. </p>

<p>Here is my code:</p>

<p>In Model:</p>

<pre><code>module.exports.getOrderBysalesOrderId = function(salesOrderId, callback){
  Order.find({salesOrderId: salesOrderId}).exec(function(err, order){
    if(err) return callback(err, null);
    callback(null, order);
  });
};
</code></pre>

<p>In Route:</p>

<pre><code>router.get('/:salesOrderId', function(req, res, next){

  var salesOrderId = req.param('salesOrderId');

  console.log('order with 1 param is called.');

  Order.getOrderBysalesOrderId(salesOrderId, function(err, order) {
        if (err) {
            return console.error(err);
        } else {
            //respond to both HTML and JSON. JSON responses require 'Accept: application/json;' in the Request Header
            res.format({

              //response in dust or jade files
              html: function(){
                  res.render('Order', {
                        title: 'Order',
                        "order" : order
                    });
              },

              //JSON response will show all orders in JSON format
              json: function(){
                  res.json(order);
              }
          });
        }
  });
});
</code></pre>

<p>Then using Ajax, I try to get the data and print it to console:</p>

<pre><code>$.ajax(
{
    type: "GET",
    url: "/Order/" + orderNo,
    dataType:"json",
    async: false,
    beforeSend: function(jqXHR, settings)
    {
        console.log(settings.url);
    },
    success: function(order)
    {
      console.log(order);
      templateData = order;
    },
    error: function(xhr, textStatus, errorThrown)
    {
        alert('ajax loading error... ... '+ url + query);
    }
});
</code></pre>

<p>Output in Console:</p>

<p><a href="https://i.stack.imgur.com/xH5dS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xH5dS.jpg" alt="enter image description here"></a></p>

<h1>Update:</h1>

<p>Here is the structure of my model:</p>

<pre><code>var mongoose = require('mongoose');

var orderSchema = new mongoose.Schema({
  salesOrderId: String,
  orderDate: Date,
  party: {type: mongoose.Schema.Types.ObjectId, ref:'Party'},
  items:[{type: mongoose.Schema.Types.ObjectId, ref:'Item'}, {quantity: Number}, {rate: Number}],
  dispatches:{
    invoiceId: Number,
    dispatchDate: Date,
    items: [{type: mongoose.Schema.Types.ObjectId, ref:'Item'}, {quantity: Number}, {rate: Number}]
  }
});
</code></pre>

<h1>Update2:</h1>

<p>When I try to get data using populate(), here  is my query:</p>

<pre><code>module.exports.getOrderBysalesOrderId = function(salesOrderId, callback){
  Order.find({salesOrderId: salesOrderId}).populate("items").exec(function(err, order){
    console.log(order);
    if(err) return callback(err, null);
    callback(null, order);
  });
};
</code></pre>

<p>Here I get error:</p>

<p><a href="https://i.stack.imgur.com/dHgLp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dHgLp.jpg" alt="enter image description here"></a></p>

<h1>Update3:</h1>

<p>Now I tried the below mentioned code in model:</p>

<pre><code>module.exports.getOrderBysalesOrderId = function(salesOrderId, callback){
  salesOrderId = mongoose.Types.ObjectId(salesOrderId);
  Order.find({salesOrderId: salesOrderId}).populate("party").exec(function(err, order){
    console.log(order);
    if(err) return callback(err, null);
    callback(null, order);
  });
};
</code></pre>

<p>Here is my db.js file:</p>

<pre><code>var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/RateDifferenceDB')
</code></pre>

<p>Now, I get another error:</p>

<p><a href="https://i.stack.imgur.com/JY24g.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JY24g.jpg" alt="enter image description here"></a></p>

<p>I also get a url error in console of browser:</p>

<p><a href="https://i.stack.imgur.com/fbCqQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fbCqQ.jpg" alt="enter image description here"></a></p>