public override WriteConcernResult Save(BsonDocument document, WriteConcern writeConcern, bool needResult) { // copy, make id, override document = CloneExternalDocument(document); var id = document.EnsureId(); bool updatedExisting = _data.ContainsKey(id); _data[id] = document; return needResult ? new WriteConcernResult(NewResponse(1, updatedExisting, null, null)) : null; }
public override WriteConcernResult Save(BsonDocument document, WriteConcern writeConcern, bool needResult) { // copy, make id, override document = CloneExternalDocument(document); var id = document.EnsureId(); bool updatedExisting = _data.ContainsKey(id); _data[id] = document; return(needResult ? new WriteConcernResult(NewResponse(1, updatedExisting, null, null)) : null); }
protected override void InsertInternal(BsonDocument document) { // make id BsonValue id; if (!document.TryGetValue(MyValue.Id, out id)) { id = document.EnsureId(); } else if (id.BsonType == BsonType.Array) { throw new InvalidOperationException("Can't use an array for _id."); } // try to add try { _data.Add(id, document); } catch (ArgumentException) { ThrowIdExists(id); } }
protected override void InsertInternal(BsonDocument document) { // make id BsonValue id; if (!document.TryGetValue(MyValue.Id, out id)) id = document.EnsureId(); else if (id.BsonType == BsonType.Array) throw new InvalidOperationException("Can't use an array for _id."); // try to add try { _data.Add(id, document); } catch (ArgumentException) { ThrowIdExists(id); } }