$wind array in mongoose node js code example

Example 1: js array of strings mongoose

var personSchema = new mongoose.Schema({
tags: [{
    type: String
}]

Example 2: add items to a list in a document monoose

const {name , id} = req.body
    Category.update(
        {_id: id}, 
        {$push: {items: {"name": name}}},{new: true, upsert: true }).exec();
        res.sendStatus(200)

Example 3: add in to array mongoose

// With { $push: { field: element } }

// Example:
const elementToPush = { a: 1, b: 2 };
const body = { $push: { arrayField: elementToPush } };
model.patch(id, body);

Tags:

Misc Example