MongoUtility.Command.Operater.InsertEmptyDocument C# (CSharp) Method

InsertEmptyDocument() public static method

插入空文档
public static InsertEmptyDocument ( MongoCollection mongoCol, bool safeMode ) : BsonValue
mongoCol MongoCollection
safeMode bool
return BsonValue
        public static BsonValue InsertEmptyDocument(MongoCollection mongoCol, bool safeMode)
        {
            var document = new BsonDocument();
            if (safeMode)
            {
                try
                {
                    mongoCol.Insert(document, WriteConcern.Acknowledged);
                    return document.GetElement(ConstMgr.KeyId).Value;
                }
                catch
                {
                    return BsonNull.Value;
                }
            }
            mongoCol.Insert(document);
            return document.GetElement(ConstMgr.KeyId).Value;
        }