Paging with the Bucket Pattern and custom _id

I am trying to implement Bucket Pattern (https://www.mongodb.com/blog/post/paging-with-the-bucket-pattern--part-2) in golang. In Java it was no problem at all, and in golang I am stocking with Error:

“Error: 66 Performing an update on the path ‘_id’ would modify the immutable field ‘_id’”.

Is it possible to disable this validation (BypassDocumentValidation has no effect on it)? Or did I missed something?

    result, err := col.UpdateOne(
		context.Background(),
		bson.M{"_id": `{$regex : /^` + companyID + `_/i}`, "count": `{"$lt": 100}`},
		bson.D{
			{Key: "$push", Value: bson.D{{Key: "events", Value: adding.FeedEvent{ID: savedID, Type: adding.FeedTypeNote}}}},
			{Key: "$set", Value: bson.D{{Key: "end", Value: ts}}},
			{Key: "$inc", Value: bson.D{{Key: "count", Value: 1}}},
			{Key: "$setOnInsert", Value: bson.D{{Key: "_id", Value: companyID + "_" + strconv.FormatInt(ts, 10)}}},
			{Key: "$setOnInsert", Value: bson.D{{Key: "start", Value: ts}}},
		},
		&options.UpdateOptions{Upsert: &valTrue, BypassDocumentValidation: &valTrue},
	)

same in JAVA, works perfectly

Query<FeedBucket> q1 = repo.createQuery(FeedBucket.class, "{'_id':/^" + companyId + "_/,'count':{$lt:100}}");
        UpdateOperations<FeedBucket> ops = repo.getMorphiaDatastore().createUpdateOperations(FeedBucket.class)
                .push("events", new FeedEvent(saved.getId().toString(), saved.getType()))
                .set("end", saved.getTs())
                .inc("count")
                .setOnInsert("_id", companyId + "_" + saved.getTs())
                .setOnInsert("start", saved.getTs());
                repo.getMorphiaDatastore().updateFirst(q1, ops, true);

my fault …
correct filter must be -

bson.M{"_id": bson.D{{Key: "$regex", Value: primitive.Regex{Pattern: "^" + companyID + "_", Options: "i"}}}, "count": bson.D{{Key: "$lt", Value: 100}}},

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.