node.js - One to Many mapping in mongoose, How to receive and process? -


the problem have 1 many mapping mongoose(mongodb). 1 order(buyer data) , many items(price,quantity,etc).

1) how should create schema the order , items, should put items in array in order?

2) data in 1 post function?

i herd can use objectid link many 1 not sure how to.

since order sounds have relative small number of items, simplest thing list of item ids:

var orderschema = new mongoose.schema({     items: [{type: mongoose.schema.types.objectid, ref: 'item'}] });  var itemschema = new mongoose.schema({     price: number,     quantity: number }); 

most uis not build entire order in single post function, it's best allow creating order , separately adding items via order.items.push(itemid).


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -