const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/test", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const AddressSchema = mongoose.Schema({
city: String,
street: String,
houseNumber: String,
});
const ContactInfoSchema = mongoose.Schema({
tel: [Number],
email: [String],
address: {
type: AddressSchema,
required: true,
},
});
const CustomerSchema = mongoose.Schema({
firstName: String,
lastName: String,
company: String,
connectInfo: ContactInfoSchema,
});
const CustomerModel = mongoose.model("Customer", CustomerSchema);
const customer = new CustomerModel({
firstName: "Ashish",
lastName: "Suthar",
company: "BitOrbits",
connectInfo: {
tel: [8154080079, 6354492692],
email: ["asissuthar@gmail.com", "contact.bitorbits@gmail.com"],
},
});
customer.save((err, cust) => {
if (err) return console.error(err);
});
CustomerModel.findOne({ firstName: "Ashish" }, (err, cust) => {
if (err) return console.error(err);
console.log(cust.connectInfo.tel[0]);
});
CustomerModel.updateOne(
{ firstName: "Ashish" },
{
$set: {
"connectInfo.tel.0": 8154099999,
},
}
);