(updated on 2019-7-2) 7 days after, finally, I solved this question. Well, my code is OK, WTF, wasted so much time. The question is my team use AliCloud(a chinese company, like Amazon, Azure), and the Mongodb has many versions, We created the DataBase a year ago, and that version, will lock the database while processing a trunsaction.
if you have some problem, hope my experence could help.
forgive my poor english...
dev enviroment : mongodb4.0 cluster with 3nodes, support transactions. .net core 2.2 (mongodb driver 2.7.2+) Robot 3T(mongod tool)
the MongoDB database will be locked 60 seconds after starting a transaction, I thought maybe the problem is lock level, but I've already tried all enums of readconcern or writeconvern, nothing helps.
here is an image: now database is locked, I cannot query data in Robot 3T, neither my web app.
I mean, before commitTransaction/abortTransaction, the database will be locked. if the transcation is a big one, complete in 30s, actually the webapp cannot read data response to other visitors.
in fact, the users of my webapp always say, why your app runs so slow (because every transcation lock the database for 0.xx second)
TransactionOptions option = new TransactionOptions(readConcern: ReadConcern.Snapshot,writeConcern: WriteConcern.W1);
ClientSessionOptions so =new ClientSessionOptions();
so.DefaultTransactionOptions = option;
var session = _dataBase.Client.StartSession();
var products = _dataBase.GetCollection<Product>("products");
var TV = new Product { Description = "Television", SKU = 4001, Price = 2000 };
session.StartTransaction(option);
try
{
products.InsertOne(session, TV);
// after the sentence , database will be locked
// before commitTransaction, the webapp cannot response, like Robot 3T, // looks like the database is locked
session.CommitTransaction();