Answers for "mongoose insertmany example"

1

mongoose insertmany example

//Mongo insert many example
   db.products.insertMany( [
      { item: "card", qty: 15 },
      { item: "envelope", qty: 20 },
      { item: "stamps" , qty: 30 }
   ] );
//mongoose
const Product = mongoose.model('Product', productSchema);
Product.insertMany([
      { item: "card", qty: 15 },
      { item: "envelope", qty: 20 },
      { item: "stamps" , qty: 30 }
   ])
Posted by: Guest on July-14-2021
1

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);
Posted by: Guest on November-19-2020

Code answers related to "mongoose insertmany example"

Code answers related to "Javascript"

Browse Popular Code Answers by Language