0

My orderschema is as follows:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var foodtruck = require('./foodtruck.js');
var payment = require('./payment.js');
var Items = require('./items.js');


var order = new Schema({
    order_status:Number,   //0 place 1 accepted 2 cooked 3 cancelled
    customer_id:{type: Schema.Types.ObjectId,ref: 'user'},
    items:[{type : Schema.Types.ObjectId, ref : 'items'}],
    user_type:Boolean,
    order_time:Date,
    order_rating:{type:Number,default:5.0},
    order_issue_comments:String,
    order_special_instruction:String,
    order_total:Number,
    order_location:String,
    order_coupon_code:String,
    payment_id:{type:Schema.Types.ObjectId,ref:'payment'}
},{ versionKey: false });


module.exports = mongoose.model('order',order);

items.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var ItemSchema = new Schema({
    no_of_times_ordered:Number,
    item_name:String,
    item_tag:String,
    item_category:String,
    item_illustrations:[String],
    item_stock:Number,
    item_quantity_ordered:{type:Number,default:0},
    item_price:Number,
    item_img:String,
    no_of_likes:Number
},{ versionKey: false });

module.exports = mongoose.model('items',ItemSchema);

Now in my items parameter, I am expecting an array. I have already achieved the successful order creation with only one item. But I am unable to put item array while making request in postman.

The following line are from the postman request

customer_id:58b9aaca50fb632134fc78f5
order_special_instruction:please add onions
order_total:50.09
order_location:seattle
order_coupon_code:AERT78
payment_id:58b9aaca50fb632134fc79a7
item_id:58ba7ae503f5cc2bf48d6932
item_quantity:2

Now how would I have multiple item_id and item_quantity in request. The parameters that I have posted above are accepted in "x-www-form-urlencoded" in postman.

1 Answers1

0

As per the discussion in comments, I suggest to use a body parser such as https://www.npmjs.com/package/body-parser to make your life easier.