Hello all,
I’m new to mongoDB and I’m a little bit lost with the error I’m facing.
My project is a javascript program running on a web browser. I have a small collection which is updated when I click on the canvas. I use collection.updateOne() to push some data inside my collection.
(Basically, it is 4 fields and each contains 1 integer. So I don’t think it’s “heavy” work for the DB)
Everything seems to be fine when I call updateOne() once but in my case, I need to call it 4 times and I think this create concurrent write operations. Then, the write operation is really slowed down and sometime I get the following error:
StitchError.js:14 Uncaught (in promise) e {message: 'failed to update documents: retry count exhausted', name: 'e', errorCode: 11, errorCodeName: 'MongoDBError', stack: 'e: failed to update documents: retry count exhaust…titch-browser-sdk/dist/browser/stitch.js:1:203137'}
Is there a way to wait for the first updateOne() to finish before calling the next one ?
here’s pieces of my code. In another file, I first call divideSubSquareInMiddle(). Method divideSubSquare() is called and this one create 4 new objects of the same class. In the constructor, I call the updateOne().
class SubSquare {
static original_pixels;
constructor(high_corner, low_corner, parent = {}, pixels = null, data){
this._parent = parent;
this._child = [];
this._high_corner = high_corner;
this._low_corner = low_corner;
this._width = low_corner[0] - high_corner[0];
this._height = low_corner[1] - high_corner[1];
if(isNaN(SubSquare.counter)){
SubSquare.counter = 0;
}else{
SubSquare.counter++;
}
this.id = SubSquare.counter;
if(this.height < 0 || this._width < 0){
console.log("ERROR: height and/or width of new SubSquare < 0");
}
if(pixels != null){
this.original_pixels = pixels;
this.computeAvg();
} else {
console.error("no pixels provided")
}
if(data != null){
this.collection = data.collection;
this.gameId = data.gameId;
this.authId = data.authId;
this.ownerId = data.ownerId;
console.log("call updateOne");
this.collection.updateOne(
{
"owner_id": this.authId,
"_id": this.gameId
},
{
"$push": {
"vertices": this.toJSON()
}
}
).then(result => console.log(result));
}else{
console.log("no data provided in SubSquare");
}
console.log("updateOne finished");
}
divideSubSquare(divider_pos){
this._child.push(new SubSquare(
this._high_corner,
divider_pos,
this,
this.original_pixels,
{"gameId": this.gameId,
"collection": this.collection,
"authId": this.authId,
"ownerId": this.ownerId}
));//TL
this._child.push(new SubSquare(
[divider_pos[0], this._high_corner[1]],
[this._low_corner[0], divider_pos[1]],
this,
this.original_pixels,
{"gameId": this.gameId,
"collection": this.collection,
"authId": this.authId,
"ownerId": this.ownerId}
));//TR
this._child.push(new SubSquare(
[this._high_corner[0], divider_pos[1]],
[divider_pos[0], this._low_corner[1]],
this,
this.original_pixels,
{"gameId": this.gameId,
"collection": this.collection,
"authId": this.authId,
"ownerId": this.ownerId}
));//BL
this._child.push(new SubSquare(
divider_pos,
this._low_corner,
this,
this.original_pixels,
{"gameId": this.gameId,
"collection": this.collection,
"authId": this.authId,
"ownerId": this.ownerId}
));//BR
}
divideSubSquareInMiddle(){
this.divideSubSquare([this.getMiddleX(), this.getMiddleY()]);
}