этот запрос работает в пн go оболочка
db.orders.updateOne({ _id: ObjectId("5e26be38c13b7149d0a95111"),
"submittedTo":ObjectId("5e2555363405363bc4bf86c2") },
{ $set: {
... "vendorOrder" : [
... {
... "_id" : ObjectId("5e26be38c13b7149d0a95113"),
... "publicationCode" : "TOI",
... "publicationName" : "Times of India",
... "editionName" : "chennai city",
... "productCode" : "TCE1",
... "subscriptionCopies" : 70,
... "tradeCopies" : 9
... },
... {
... "_id" : ObjectId("5e26be38c13b7149d0a95112"),
... "publicationCode" : "ET",
... "publicationName" : "Economic Times",
... "editionName" : "chennai city",
... "productCode" : "ECE1",
... "subscriptionCopies" : 20,
... "tradeCopies" : 4
... }
... ]}})
пн go ответ оболочки: { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
но не работает в nodejs: вот что я пробовал до сих пор query1:
exports.editOrder = async (req, res, next) => {
const { orderId, dealerId, vendorOrder } = req.body;
try {
const orders = await Order.updateOne(
{
_id: orderId,
submittedTo:dealerId
},
{ $set: { vendorOrder } }
);
res.status(200).json({
orders,
message: "order submitted"
});
} catch (error) {
res.send(error);
}
};
query2
exports.editOrder = async (req, res, next) => {
const { orderId, dealerId, vendorOrder } = req.body;
try {
const orders = await Order.updateOne(
{
_id: mongoose.Types.ObjectId(orderId),
submittedTo: mongoose.Types.ObjectId(dealerId)
},
{ $set: { vendorOrder: vendorOrder } }
);
res.status(200).json({
orders,
message: "order submitted"
});
} catch (error) {
res.send(error);
}
};
запрос 3 : с двойным "" кодом остатка точно такой же *
const { orderId, dealerId, vendorOrder } = req.body;
try {
const orders = await Order.updateOne(
{
"_id": mongoose.Types.ObjectId(orderId),
"submittedTo": mongoose.Types.ObjectId(dealerId)
},
{ $set: { "vendorOrder": vendorOrder } }
);
POSTMAN JSON:
{
"orderId":"5e26be38c13b7149d0a95111",
"submittedTo":"5e2555363405363bc4bf86c2",
"vendorOrder" : [
{
"_id" : "5e26be38c13b7149d0a95113",
"publicationCode" : "TOI",
"publicationName" : "Times of India",
"editionName" : "chennai city",
"productCode" : "TCE1",
"subscriptionCopies" : 70,
"tradeCopies" : 90
},
{
"_id" : "5e26be38c13b7149d0a95112",
"publicationCode" : "ET",
"publicationName" : "Economic Times",
"editionName" : "chennai city",
"productCode" : "ECE1",
"subscriptionCopies" : 20,
"tradeCopies" : 40
}
]
ПОЧТОВЫЙ ОТВЕТ
{
"orders": {
"n": 0,
"nModified": 0,
"ok": 1
},
"message": "order submitted"
}