1

I want to assign the same id value to roomID where the objects have the same type.

const Item = new Schema({
  roomID: { type: String},
  type: { type: String }
});

const Order = new Schema({
  items: [{ type: Item }]
});

I want the output to be something like this:

{
  id: "1234567890",
  items: [
    {
      roomID:"5efd1db1803ec01b1c590e23"
      type: "first",
      // more data
    },
    {
      roomID:"5efd1db1803ec01b1c590e23"
      type: "first",
      // more data
    },
    {
      roomID:"5efd1db1803ec01b1c590e82"
      type: "second",
      // more data
    },
  ],
};
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.