我有以下的bulk_write来将数据集中的每个文档更新插入到集合中。
data = [] # list of dicts/documents
mongo = MongoClient('some_host')
db = mongo['some_db']
collection = db['some_collection']
operations = [UpdateOne({'_id': d['_id']}, {'$set': d}, upsert=True) for d in data]
result = collection.bulk_write(operations)
Run Code Online (Sandbox Code Playgroud)
它在本地 MongoDB 服务器上运行良好,但在 AWS DocumentDB 上运行时收到以下错误消息。有一种解决方法是我删除并插入每条记录,但想了解为什么会发生这种情况并使用更新而不是删除+插入
pymongo.errors.OperationFailure: Retryable writes are not supported, full error: {'ok': 0.0, 'code': 301, 'errmsg': 'Retryable writes are not supported', 'operationTime': Timestamp(1638883052, 1)}
我正在使用express,mongodb(atlas cloud)和mongoose工作我的第一个node.js rest api,当我尝试发出.remove请求时,我收到此错误:
{
"error": {
"name": "MongoError",
"message": "Cannot use (or request) retryable writes with limit=0",
"driver": true,
"index": 0,
"code": 72,
"errmsg": "Cannot use (or request) retryable writes with limit=0"
}
Run Code Online (Sandbox Code Playgroud)
这是我的要求:
router.delete('/:productId', (req, res, next) => {
const id = req.params.productId;
Product.remove({ _id: id })
.exec()
.then(result => {
res.status(200).json(result);
})
.catch(err => {
console.log(err);
res.status(500).json({
error: err
})
}); ;
});
Run Code Online (Sandbox Code Playgroud)