[英]Can't add array to mongodb
我正在嘗試向 mongodb 發送一個數組,但是res.json(user)
返回一個空的biddingGroup:[]
並且 mongodb 文檔永遠不會出現字段 bidingGroup。 我查看了堆棧帖子並看到了有關架構的建議。 我試過了
biddingGroup: [{type: String}],
biddingGroup: [String],
biddingGroup: {type: String},
我還沒有找到捕獲數據的工作模式。
我什至也硬編碼了 bidGroup: ['test'] ,但它從未出現過。
應用程序.js
app.put('/api/listings/:id', (req, res) =>
Post.update({
id: req.query.id
}, {
$set: {
currentBid: req.query.currentBid,
lastBidTimeStamp: req.params.lastBidTimeStamp,
biddingGroup: ['test']
}
}, {
multi: false //set to false to ensure only one document gets updated
}).exec().then(data => {
console.log(data);
}, err => {
console.log(err);
})
);
任何幫助表示贊賞。
您需要在最后使用exec()
來運行查詢。 那就是實際運行請求並返回 promise 的 function。 另外,您對update
function 的使用通常已關閉。
嘗試這個:
Post.update({
id: req.query.id
}, {
$set: {
currentBid: req.query.currentBid,
lastBidTimeStamp: req.params.lastBidTimeStamp,
biddingGroup: ['test']
}
}, {
multi: false //set to false to ensure only one document gets updated
}).exec().then(data => {
console.log(data);
}, err => {
console.log(err);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.