diff --git a/FunctionForm/Operation/frmCollectionIndex.Designer.cs b/FunctionForm/Operation/frmCollectionIndex.Designer.cs
index d1295224..5b7e7eaf 100644
--- a/FunctionForm/Operation/frmCollectionIndex.Designer.cs
+++ b/FunctionForm/Operation/frmCollectionIndex.Designer.cs
@@ -38,6 +38,7 @@ private void InitializeComponent()
this.tabIndexMgr = new System.Windows.Forms.TabControl();
this.tabCurrentIndex = new System.Windows.Forms.TabPage();
this.tabIndexManager = new System.Windows.Forms.TabPage();
+ this.txtPartialIndexes = new System.Windows.Forms.TextBox();
this.chkPartialIndexes = new System.Windows.Forms.CheckBox();
this.numTTL = new System.Windows.Forms.NumericUpDown();
this.chkExpireData = new System.Windows.Forms.CheckBox();
@@ -52,7 +53,7 @@ private void InitializeComponent()
this.ctlIndexCreate3 = new MongoGUICtl.CtlIndexCreate();
this.ctlIndexCreate2 = new MongoGUICtl.CtlIndexCreate();
this.ctlIndexCreate1 = new MongoGUICtl.CtlIndexCreate();
- this.txtPartialIndexes = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
this.tabIndexMgr.SuspendLayout();
this.tabCurrentIndex.SuspendLayout();
this.tabIndexManager.SuspendLayout();
@@ -124,6 +125,7 @@ private void InitializeComponent()
this.tabIndexManager.Controls.Add(this.numTTL);
this.tabIndexManager.Controls.Add(this.chkExpireData);
this.tabIndexManager.Controls.Add(this.txtIndexName);
+ this.tabIndexManager.Controls.Add(this.label1);
this.tabIndexManager.Controls.Add(this.lblIndexName);
this.tabIndexManager.Controls.Add(this.chkIsUnique);
this.tabIndexManager.Controls.Add(this.chkIsSparse);
@@ -143,6 +145,14 @@ private void InitializeComponent()
this.tabIndexManager.Tag = "CollectionIndexTabManager";
this.tabIndexManager.Text = "Create Index";
//
+ // txtPartialIndexes
+ //
+ this.txtPartialIndexes.Location = new System.Drawing.Point(167, 283);
+ this.txtPartialIndexes.Multiline = true;
+ this.txtPartialIndexes.Name = "txtPartialIndexes";
+ this.txtPartialIndexes.Size = new System.Drawing.Size(473, 122);
+ this.txtPartialIndexes.TabIndex = 23;
+ //
// chkPartialIndexes
//
this.chkPartialIndexes.AutoSize = true;
@@ -280,16 +290,17 @@ private void InitializeComponent()
this.ctlIndexCreate1.Size = new System.Drawing.Size(592, 37);
this.ctlIndexCreate1.TabIndex = 13;
//
- // txtPartialIndexes
+ // label1
//
- this.txtPartialIndexes.Location = new System.Drawing.Point(167, 257);
- this.txtPartialIndexes.Multiline = true;
- this.txtPartialIndexes.Name = "txtPartialIndexes";
- this.txtPartialIndexes.Size = new System.Drawing.Size(473, 148);
- this.txtPartialIndexes.TabIndex = 23;
- this.txtPartialIndexes.Text = "Partial Filter Expression";
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(25, 283);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(136, 15);
+ this.label1.TabIndex = 18;
+ this.label1.Tag = "";
+ this.label1.Text = "Partial Filter Expression";
//
- // FrmCollectionIndex
+ // frmCollectionIndex
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@@ -300,7 +311,7 @@ private void InitializeComponent()
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
- this.Name = "FrmCollectionIndex";
+ this.Name = "frmCollectionIndex";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Tag = "CollectionIndexTitle";
this.Text = "Index Management";
@@ -337,5 +348,6 @@ private void InitializeComponent()
private NumericUpDown numTTL;
private CheckBox chkPartialIndexes;
private TextBox txtPartialIndexes;
+ private Label label1;
}
}
\ No newline at end of file
diff --git a/FunctionForm/Operation/frmCollectionIndex.cs b/FunctionForm/Operation/frmCollectionIndex.cs
index 37d2a521..af28874c 100644
--- a/FunctionForm/Operation/frmCollectionIndex.cs
+++ b/FunctionForm/Operation/frmCollectionIndex.cs
@@ -73,36 +73,43 @@ private void cmdDelIndex_Click(object sender, EventArgs e)
///
private void cmdAddIndex_Click(object sender, EventArgs e)
{
- var ascendingKey = new List();
- var descendingKey = new List();
- var geoSpatialKey = string.Empty;
+ //Index UIOption
+ var uiOption = new Operater.IndexOption();
+ uiOption.AscendingKey = new List();
+ uiOption.DescendingKey = new List();
+ uiOption.TextKey = new List();
+
var firstKey = string.Empty;
- var textKey = string.Empty;
for (var i = 0; i < 5; i++)
{
- var ctl = (CtlIndexCreate) Controls.Find("ctlIndexCreate" + (i + 1), true)[0];
+ var ctl = (CtlIndexCreate)Controls.Find("ctlIndexCreate" + (i + 1), true)[0];
if (ctl.KeyName == string.Empty) continue;
firstKey = ctl.KeyName.Trim();
switch (ctl.IndexKeyType)
{
- case EnumMgr.IndexType.Ascending:
- ascendingKey.Add(ctl.KeyName.Trim());
+ case EnumMgr.IndexType.GeoSpatialHaystack:
+ uiOption.GeoSpatialHaystackKey = ctl.KeyName.Trim();
break;
- case EnumMgr.IndexType.Descending:
- descendingKey.Add(ctl.KeyName.Trim());
+ case EnumMgr.IndexType.GeoSpatialSpherical:
+ uiOption.GeoSpatialSphericalKey = ctl.KeyName.Trim();
break;
case EnumMgr.IndexType.GeoSpatial:
- geoSpatialKey = ctl.KeyName.Trim();
+ uiOption.GeoSpatialKey = ctl.KeyName.Trim();
+ break;
+ case EnumMgr.IndexType.Ascending:
+ uiOption.AscendingKey.Add(ctl.KeyName.Trim());
+ break;
+ case EnumMgr.IndexType.Descending:
+ uiOption.DescendingKey.Add(ctl.KeyName.Trim());
break;
case EnumMgr.IndexType.Text:
- textKey = ctl.KeyName.Trim();
+ uiOption.TextKey.Add(ctl.KeyName.Trim());
break;
- default:
+ case EnumMgr.IndexType.Hashed:
+ uiOption.HashedKey = ctl.KeyName.Trim();
break;
}
}
- //Index UIOption
- var uiOption = new Operater.IndexOption();
uiOption.IsBackground = chkIsBackground.Checked;
uiOption.IsDropDups = chkIsDroppedDups.Checked;
uiOption.IsSparse = chkIsSparse.Checked;
@@ -110,14 +117,10 @@ private void cmdAddIndex_Click(object sender, EventArgs e)
uiOption.IsExpireData = chkExpireData.Checked;
//Partial Indexes
uiOption.IsPartial = chkPartialIndexes.Checked;
- uiOption.Ttl = (int) numTTL.Value;
- uiOption.AscendingKey = ascendingKey;
- uiOption.DescendingKey = descendingKey;
- uiOption.GeoSpatialKey = geoSpatialKey;
+ uiOption.Ttl = (int)numTTL.Value;
uiOption.FirstKey = firstKey;
- uiOption.TextKey = textKey;
uiOption.IndexName = txtIndexName.Text;
- //Partial Indexes
+ //Partial Condition
uiOption.PartialCondition = txtPartialIndexes.Text;
var strMessageTitle = string.Empty;
var strMessageContent = string.Empty;
diff --git a/MongoCola/Release Note_Ver2.0.txt b/MongoCola/Release Note_Ver2.0.txt
index 14447686..cd959cd2 100644
--- a/MongoCola/Release Note_Ver2.0.txt
+++ b/MongoCola/Release Note_Ver2.0.txt
@@ -68,6 +68,7 @@ CSharp Mongo Driver 2.4.0-beta1
5. ML插件化
6. 修正了切断连接无效的问题
7. NetCore和Net版本条件编译
+8. BsonDocument树形表示优化
###聚合
1. $indexStats $stage,$sortByCount(From MongoDB3.4), $sample, $unwind
@@ -77,4 +78,4 @@ CSharp Mongo Driver 2.4.0-beta1
###mongobooster功能的借鉴
1. 增加了MongoDB官方文档的链接
-2. BsonGuidRepresentation概念的引入
\ No newline at end of file
+2. BsonGuidRepresentation概念的引入
diff --git a/MongoGUICtl/ctlIndexCreate.Designer.cs b/MongoGUICtl/ctlIndexCreate.Designer.cs
index 50be65d4..a375bfe9 100644
--- a/MongoGUICtl/ctlIndexCreate.Designer.cs
+++ b/MongoGUICtl/ctlIndexCreate.Designer.cs
@@ -31,38 +31,11 @@ protected override void Dispose(bool disposing)
///
private void InitializeComponent()
{
- this.radAscendingKey = new System.Windows.Forms.RadioButton();
- this.radDescendingKey = new System.Windows.Forms.RadioButton();
this.lblKeyName = new System.Windows.Forms.Label();
- this.radGeoSpatial = new System.Windows.Forms.RadioButton();
this.cmbKeyName = new System.Windows.Forms.ComboBox();
- this.radText = new System.Windows.Forms.RadioButton();
+ this.cmbIndexKeyType = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
- // radAscendingKey
- //
- this.radAscendingKey.AutoSize = true;
- this.radAscendingKey.Checked = true;
- this.radAscendingKey.Location = new System.Drawing.Point(301, 6);
- this.radAscendingKey.Name = "radAscendingKey";
- this.radAscendingKey.Size = new System.Drawing.Size(41, 16);
- this.radAscendingKey.TabIndex = 1;
- this.radAscendingKey.TabStop = true;
- this.radAscendingKey.Tag = "Index_Asce";
- this.radAscendingKey.Text = "Asc";
- this.radAscendingKey.UseVisualStyleBackColor = true;
- //
- // radDescendingKey
- //
- this.radDescendingKey.AutoSize = true;
- this.radDescendingKey.Location = new System.Drawing.Point(356, 6);
- this.radDescendingKey.Name = "radDescendingKey";
- this.radDescendingKey.Size = new System.Drawing.Size(41, 16);
- this.radDescendingKey.TabIndex = 2;
- this.radDescendingKey.Tag = "Index_Desc";
- this.radDescendingKey.Text = "Des";
- this.radDescendingKey.UseVisualStyleBackColor = true;
- //
// lblKeyName
//
this.lblKeyName.AutoSize = true;
@@ -73,17 +46,6 @@ private void InitializeComponent()
this.lblKeyName.Tag = "ctlIndexCreate_Index";
this.lblKeyName.Text = "IndexFiled";
//
- // radGeoSpatial
- //
- this.radGeoSpatial.AutoSize = true;
- this.radGeoSpatial.Location = new System.Drawing.Point(406, 6);
- this.radGeoSpatial.Name = "radGeoSpatial";
- this.radGeoSpatial.Size = new System.Drawing.Size(41, 16);
- this.radGeoSpatial.TabIndex = 5;
- this.radGeoSpatial.TabStop = true;
- this.radGeoSpatial.Text = "Geo";
- this.radGeoSpatial.UseVisualStyleBackColor = true;
- //
// cmbKeyName
//
this.cmbKeyName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -93,28 +55,23 @@ private void InitializeComponent()
this.cmbKeyName.Size = new System.Drawing.Size(213, 20);
this.cmbKeyName.TabIndex = 6;
//
- // radText
+ // cmbIndexKeyType
//
- this.radText.AutoSize = true;
- this.radText.Location = new System.Drawing.Point(457, 6);
- this.radText.Name = "radText";
- this.radText.Size = new System.Drawing.Size(47, 16);
- this.radText.TabIndex = 7;
- this.radText.TabStop = true;
- this.radText.Text = "Text";
- this.radText.UseVisualStyleBackColor = true;
+ this.cmbIndexKeyType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.cmbIndexKeyType.FormattingEnabled = true;
+ this.cmbIndexKeyType.Location = new System.Drawing.Point(310, 3);
+ this.cmbIndexKeyType.Name = "cmbIndexKeyType";
+ this.cmbIndexKeyType.Size = new System.Drawing.Size(150, 20);
+ this.cmbIndexKeyType.TabIndex = 7;
//
- // ctlIndexCreate
+ // CtlIndexCreate
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Transparent;
- this.Controls.Add(this.radText);
+ this.Controls.Add(this.cmbIndexKeyType);
this.Controls.Add(this.cmbKeyName);
- this.Controls.Add(this.radGeoSpatial);
this.Controls.Add(this.lblKeyName);
- this.Controls.Add(this.radDescendingKey);
- this.Controls.Add(this.radAscendingKey);
this.Name = "CtlIndexCreate";
this.Size = new System.Drawing.Size(524, 28);
this.ResumeLayout(false);
@@ -123,12 +80,8 @@ private void InitializeComponent()
}
#endregion
-
- private RadioButton radAscendingKey;
- private RadioButton radDescendingKey;
private Label lblKeyName;
- private RadioButton radGeoSpatial;
private ComboBox cmbKeyName;
- private RadioButton radText;
+ private ComboBox cmbIndexKeyType;
}
}
diff --git a/MongoGUICtl/ctlIndexCreate.cs b/MongoGUICtl/ctlIndexCreate.cs
index f7222af5..684a8570 100644
--- a/MongoGUICtl/ctlIndexCreate.cs
+++ b/MongoGUICtl/ctlIndexCreate.cs
@@ -17,37 +17,19 @@ public CtlIndexCreate()
GuiConfig.Translateform(Controls);
if (RuntimeMongoDbContext.GetCurrentCollection() != null)
{
- foreach (
- var fieldName in
- MongoHelper.GetCollectionSchame(RuntimeMongoDbContext.GetCurrentCollection())
- )
+ foreach (var fieldName in MongoHelper.GetCollectionSchame(RuntimeMongoDbContext.GetCurrentCollection()))
{
cmbKeyName.Items.Add(fieldName);
}
}
+ Common.Utility.FillComberWithEnum(cmbIndexKeyType, typeof(EnumMgr.IndexType), true);
}
public EnumMgr.IndexType IndexKeyType
{
get
{
- if (radAscendingKey.Checked)
- {
- return EnumMgr.IndexType.Ascending;
- }
- if (radDescendingKey.Checked)
- {
- return EnumMgr.IndexType.Descending;
- }
- if (radGeoSpatial.Checked)
- {
- return EnumMgr.IndexType.GeoSpatial;
- }
- if (radText.Checked)
- {
- return EnumMgr.IndexType.Text;
- }
- return EnumMgr.IndexType.Ascending;
+ return (EnumMgr.IndexType)cmbIndexKeyType.SelectedIndex;
}
}
diff --git a/MongoGUICtl/ctlTreeViewColumns.cs b/MongoGUICtl/ctlTreeViewColumns.cs
index 1e462349..cd1264fd 100644
--- a/MongoGUICtl/ctlTreeViewColumns.cs
+++ b/MongoGUICtl/ctlTreeViewColumns.cs
@@ -203,6 +203,14 @@ private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if (mElement.Value != null)
{
+ if (mElement.Value.IsBsonDocument)
+ {
+ strColumnText = "{ " + mElement.Value.AsBsonDocument.ElementCount + " Fields }";
+ }
+ if (mElement.Value.IsBsonArray)
+ {
+ strColumnText = "{ " + mElement.Value.AsBsonArray.Count + " Items }";
+ }
if (!mElement.Value.IsBsonDocument && !mElement.Value.IsBsonArray)
{
strColumnText = GetDisplayString(ref mElement);
@@ -213,6 +221,14 @@ private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
if (mValue != null)
{
//Type这里已经有表示Type的标识了,这里就不重复显示了。
+ if (mValue.IsBsonDocument)
+ {
+ if (e.Node.Level > 0) strColumnText = "{ " + mValue.AsBsonDocument.ElementCount + " Fields }";
+ }
+ if (mValue.IsBsonArray)
+ {
+ if (e.Node.Level > 0) strColumnText = "{ " + mValue.AsBsonArray.Count + " Items }";
+ }
if (!mValue.IsBsonDocument && !mValue.IsBsonArray)
{
if (e.Node.Level > 0)
diff --git a/MongoUtilityCore/Basic/EnumMgr.cs b/MongoUtilityCore/Basic/EnumMgr.cs
index f89d9e91..56067976 100644
--- a/MongoUtilityCore/Basic/EnumMgr.cs
+++ b/MongoUtilityCore/Basic/EnumMgr.cs
@@ -14,10 +14,12 @@ public enum ExportType
/// Excel
///
Excel,
+
///
/// Text
///
Text,
+
///
/// Xml
///
@@ -40,14 +42,71 @@ public enum IndexType
Descending,
///
- /// Geo
+ /// Hashed
///
- GeoSpatial,
+ Hashed,
///
/// 拉丁语的全文检索(Since mongodb 2.2.4)
///
- Text
+ Text,
+
+ ///
+ /// GeoSpatial(2d)
+ ///
+ GeoSpatial,
+
+ ///
+ /// GeoSpatial Spherical(2dsphere)
+ ///
+ GeoSpatialSpherical,
+
+ ///
+ /// Geo Haystack
+ ///
+ GeoSpatialHaystack
+
+ }
+
+ ///
+ /// Key String
+ ///
+ ///
+ ///
+ public static string GetKeyString(IndexKeysDocument keys)
+ {
+ var keyString = string.Empty;
+ foreach (var key in keys.Elements)
+ {
+ keyString += key.Name + ":";
+ switch (key.Value.ToString())
+ {
+ case "1":
+ keyString += IndexType.Ascending.ToString();
+ break;
+ case "-1":
+ keyString += IndexType.Descending.ToString();
+ break;
+ case "2d":
+ keyString += IndexType.GeoSpatial.ToString();
+ break;
+ case "2dsphere":
+ keyString += IndexType.GeoSpatialSpherical.ToString();
+ break;
+ case "geoHaystack":
+ keyString += IndexType.GeoSpatialHaystack.ToString();
+ break;
+ case "hashed":
+ keyString += IndexType.Hashed.ToString();
+ break;
+ case "text":
+ keyString += IndexType.Text.ToString();
+ break;
+ }
+ keyString += ";";
+ }
+ keyString = "[" + keyString.TrimEnd(";".ToArray()) + "]";
+ return keyString;
}
///
@@ -110,6 +169,7 @@ public enum PrimaryVersion
/// Version 3.2.0
///
V320 = 320,
+
///
/// Version 3.4.0
///
@@ -172,36 +232,6 @@ public enum TextSearchLanguageForEnterprise
TraditionalChinese
}
- ///
- /// Key String
- ///
- ///
- ///
- public static string GetKeyString(IndexKeysDocument keys)
- {
- var keyString = string.Empty;
- foreach (var key in keys.Elements)
- {
- keyString += key.Name + ":";
- switch (key.Value.ToString())
- {
- case "1":
- keyString += IndexType.Ascending.ToString();
- break;
- case "-1":
- keyString += IndexType.Descending.ToString();
- break;
- case "2d":
- keyString += IndexType.GeoSpatial.ToString();
- break;
- case "text":
- keyString += IndexType.Text.ToString();
- break;
- }
- keyString += ";";
- }
- keyString = "[" + keyString.TrimEnd(";".ToArray()) + "]";
- return keyString;
- }
+
}
}
\ No newline at end of file
diff --git a/MongoUtilityCore/Command/Collection.cs b/MongoUtilityCore/Command/Collection.cs
index a19df213..e1f3d96e 100644
--- a/MongoUtilityCore/Command/Collection.cs
+++ b/MongoUtilityCore/Command/Collection.cs
@@ -40,8 +40,7 @@ public static bool IsSystemCollection(string mongoDbName, string mongoColName)
//config数据库,默认为系统
//local数据库,默认为系统
//系统文件
- if (mongoColName.StartsWith("system."))
- return true;
+ if (mongoColName.StartsWith("system.")) return true;
return mongoColName.StartsWith("fs.") || IsSystemDataBase(mongoDbName);
}
@@ -86,37 +85,35 @@ public static bool RenameCollection(string strOldCollectionName, string strNewCo
{
return
RuntimeMongoDbContext.GetCurrentDataBase()
- .RenameCollection(strOldCollectionName, strNewCollectionName)
- .Ok;
+ .RenameCollection(strOldCollectionName, strNewCollectionName).Ok;
}
///
///
- ///
+ ///
///
///
///
- public static bool CreateIndex(IndexOption uiOption, ref string strMessageTitle, ref string strMessageContent)
+ public static bool CreateIndex(IndexOption KeyOptions, ref string strMessageTitle, ref string strMessageContent)
{
- var result = true;
var option = new IndexOptionsBuilder();
- option.SetBackground(uiOption.IsBackground);
- option.SetDropDups(uiOption.IsDropDups);
- option.SetSparse(uiOption.IsSparse);
- option.SetUnique(uiOption.IsUnique);
- if (uiOption.IsPartial)
+ option.SetBackground(KeyOptions.IsBackground);
+ option.SetDropDups(KeyOptions.IsDropDups);
+ option.SetSparse(KeyOptions.IsSparse);
+ option.SetUnique(KeyOptions.IsUnique);
+ if (KeyOptions.IsPartial)
{
- IMongoQuery query = (QueryDocument)BsonDocument.Parse(uiOption.PartialCondition);
+ IMongoQuery query = (QueryDocument)BsonDocument.Parse(KeyOptions.PartialCondition);
option.SetPartialFilterExpression(query);
}
- if (uiOption.IsExpireData)
+ if (KeyOptions.IsExpireData)
{
//TTL的限制条件很多
//http://docs.mongodb.org/manual/tutorial/expire-data/
//不能是组合键
var canUseTtl = true;
- if (uiOption.AscendingKey.Count + uiOption.DescendingKey.Count +
- (string.IsNullOrEmpty(uiOption.GeoSpatialKey) ? 0 : 1) != 1)
+ if (KeyOptions.AscendingKey.Count + KeyOptions.DescendingKey.Count +
+ (string.IsNullOrEmpty(KeyOptions.GeoSpatialKey) ? 0 : 1) != 1)
{
strMessageTitle = "Can't Set TTL";
strMessageContent = "the TTL index may not be compound (may not have multiple fields).";
@@ -125,7 +122,7 @@ public static bool CreateIndex(IndexOption uiOption, ref string strMessageTitle,
else
{
//不能是_id
- if (uiOption.FirstKey == ConstMgr.KeyId)
+ if (KeyOptions.FirstKey == ConstMgr.KeyId)
{
strMessageTitle = "Can't Set TTL";
strMessageContent =
@@ -147,97 +144,140 @@ public static bool CreateIndex(IndexOption uiOption, ref string strMessageTitle,
"the indexed field must be a date BSON type. If the field does not have a date type, the data will not expire." +
Environment.NewLine +
"if the field holds an array, and there are multiple date-typed data in the index, the document will expire when the lowest (i.e. earliest) matches the expiration threshold.";
- option.SetTimeToLive(new TimeSpan(0, 0, uiOption.Ttl));
+ option.SetTimeToLive(new TimeSpan(0, 0, KeyOptions.Ttl));
}
}
- var totalIndex = uiOption.AscendingKey.Count + uiOption.DescendingKey.Count +
- (string.IsNullOrEmpty(uiOption.GeoSpatialKey) ? 0 : 1) +
- (string.IsNullOrEmpty(uiOption.TextKey) ? 0 : 1);
- if (uiOption.IndexName != string.Empty &&
- !RuntimeMongoDbContext.GetCurrentCollection().IndexExists(uiOption.IndexName) && totalIndex != 0)
+ var totalIndex = KeyOptions.AscendingKey.Count + KeyOptions.DescendingKey.Count + KeyOptions.TextKey.Count;
+ totalIndex += string.IsNullOrEmpty(KeyOptions.GeoSpatialHaystackKey) ? 0 : 1;
+ totalIndex += string.IsNullOrEmpty(KeyOptions.GeoSpatialKey) ? 0 : 1;
+ totalIndex += string.IsNullOrEmpty(KeyOptions.GeoSpatialSphericalKey) ? 0 : 1;
+
+ if (string.IsNullOrEmpty(KeyOptions.IndexName) || totalIndex == 0 ||
+ RuntimeMongoDbContext.GetCurrentCollection().IndexExists(KeyOptions.IndexName))
{
- option.SetName(uiOption.IndexName);
- try
- {
- //暂时要求只能一个TextKey
- if (!string.IsNullOrEmpty(uiOption.TextKey))
- {
- var textKeysDoc = new IndexKeysDocument { { uiOption.TextKey, "text" } };
- RuntimeMongoDbContext.GetCurrentCollection().CreateIndex(textKeysDoc, option);
- }
- else
- {
- CreateMongoIndex(uiOption.AscendingKey.ToArray(), uiOption.DescendingKey.ToArray(),
- uiOption.GeoSpatialKey,
- option, RuntimeMongoDbContext.GetCurrentCollection());
- }
- strMessageTitle = "Index Add Completed!";
- strMessageContent = "IndexName:" + uiOption.IndexName + " is add to collection.";
- }
- catch
- {
- strMessageTitle = "Index Add Failed!";
- strMessageContent = "IndexName:" + uiOption.IndexName;
- result = false;
- }
+ strMessageTitle = "Index Add Failed!";
+ strMessageContent = "Please Check the index information.";
+ return false;
+ }
+ option.SetName(KeyOptions.IndexName);
+ if (CreateMongoIndex(KeyOptions, option, RuntimeMongoDbContext.GetCurrentCollection()))
+ {
+ strMessageTitle = "Index Add Completed!";
+ strMessageContent = "IndexName:" + KeyOptions.IndexName + " is add to collection.";
+ return true;
}
else
{
strMessageTitle = "Index Add Failed!";
- strMessageContent = "Please Check the index information.";
- result = false;
+ strMessageContent = "IndexName:" + KeyOptions.IndexName;
+ return false;
}
- return result;
}
///
+ /// 添加索引
///
- public static void ReIndex()
+ ///
+ ///
+ ///
+ ///
+ public static bool CreateMongoIndex(IndexOption IdxOpt,
+ IndexOptionsBuilder option, MongoCollection currentCollection)
{
- RuntimeMongoDbContext.GetCurrentCollection().ReIndex();
+ var mongoCol = currentCollection;
+ var indexkeys = new IndexKeysBuilder();
+ if (!string.IsNullOrEmpty(IdxOpt.GeoSpatialHaystackKey)) indexkeys.GeoSpatialHaystack(IdxOpt.GeoSpatialHaystackKey);
+ if (!string.IsNullOrEmpty(IdxOpt.GeoSpatialKey)) indexkeys.GeoSpatial(IdxOpt.GeoSpatialKey);
+ if (!string.IsNullOrEmpty(IdxOpt.GeoSpatialSphericalKey)) indexkeys.GeoSpatialSpherical(IdxOpt.GeoSpatialSphericalKey);
+ indexkeys.Ascending(IdxOpt.AscendingKey.ToArray());
+ indexkeys.Descending(IdxOpt.DescendingKey.ToArray());
+ indexkeys.Text(IdxOpt.TextKey.ToArray());
+ var result = mongoCol.CreateIndex(indexkeys, option);
+ return result.Response.GetElement("ok").Value.AsBoolean;
}
///
- /// Create Collection
+ /// 索引选项
///
- ///
- ///
- ///
- ///
- public static bool CreateCollection(string strObjTag, string collectionName, MongoDatabase mongoDb)
+ public struct IndexOption
{
- //不支持中文 JIRA ticket is created : SERVER-4412
- //SERVER-4412已经在2013/03解决了
- //collection names are limited to 121 bytes after converting to UTF-8.
- collectionName = collectionName.Trim();
- if (mongoDb == null) return false;
- if (mongoDb.CollectionExists(collectionName)) return false;
- mongoDb.CreateCollection(collectionName);
- return true;
- }
+ ///
+ /// IsBackground
+ ///
+ public bool IsBackground;
+ ///
+ /// IsDropDups
+ ///
+ public bool IsDropDups;
+ ///
+ /// IsSparse
+ ///
+ public bool IsSparse;
+ ///
+ /// IsUnique
+ ///
+ public bool IsUnique;
+ ///
+ /// 是否为 Partial Indexes
+ ///
+ public bool IsPartial;
+ ///
+ /// IsExpireData
+ ///
+ public bool IsExpireData;
+ ///
+ /// Ttl
+ ///
+ public int Ttl;
+ ///
+ /// IndexName
+ ///
+ public string IndexName;
+ ///
+ /// AscendingKey
+ ///
+ public List AscendingKey;
+ ///
+ /// DescendingKey
+ ///
+ public List DescendingKey;
+ ///
+ /// GeoSpatialHaystackKey
+ ///
+ public string GeoSpatialHaystackKey;
+ ///
+ /// GeoSpatialSphericalKey
+ ///
+ public string GeoSpatialSphericalKey;
+ ///
+ /// GeoSpatialKey
+ ///
+ public string GeoSpatialKey;
+ ///
+ /// HashedKey
+ ///
+ public string HashedKey;
+ ///
+ /// FirstKey
+ ///
+ public string FirstKey;
+ ///
+ /// TextKey
+ ///
+ public List TextKey;
+
+ ///
+ /// Partial Indexes 的条件
+ ///
+ public string PartialCondition;
+ }
///
- /// 添加索引
+ /// ReIndex
///
- ///
- ///
- ///
- ///
- ///
- ///
- public static bool CreateMongoIndex(string[] ascendingKey, string[] descendingKey, string geoSpatialKey,
- IndexOptionsBuilder option, MongoCollection currentCollection)
+ public static void ReIndex()
{
- var mongoCol = currentCollection;
- var indexkeys = new IndexKeysBuilder();
- if (!string.IsNullOrEmpty(geoSpatialKey))
- {
- indexkeys.GeoSpatial(geoSpatialKey);
- }
- indexkeys.Ascending(ascendingKey);
- indexkeys.Descending(descendingKey);
- mongoCol.CreateIndex(indexkeys, option);
- return true;
+ RuntimeMongoDbContext.GetCurrentCollection().ReIndex();
}
///
@@ -259,6 +299,26 @@ public static bool DropMongoIndex(string indexName, MongoCollection mongoCol)
return true;
}
+
+ ///
+ /// Create Collection
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool CreateCollection(string strObjTag, string collectionName, MongoDatabase mongoDb)
+ {
+ //不支持中文 JIRA ticket is created : SERVER-4412
+ //SERVER-4412已经在2013/03解决了
+ //collection names are limited to 121 bytes after converting to UTF-8.
+ collectionName = collectionName.Trim();
+ if (mongoDb == null) return false;
+ if (mongoDb.CollectionExists(collectionName)) return false;
+ mongoDb.CreateCollection(collectionName);
+ return true;
+ }
+
///
/// 复制表
///
@@ -278,65 +338,16 @@ public static bool CopyCollection(MongoDatabase fromDb, MongoDatabase toDb, stri
var result = toCollection.InsertBatch(fromCollection.FindAll()).ToList();
if (isIndex)
{
- //toCollection.DropAllIndexes();
- //foreach (var index in fromCollection.GetIndexes())
- //{
- // toCollection.CreateIndex(index.)
- //}
+ //TODO:
}
return result.Count > 0 && result[0].Response.Contains("ok") && result[0].Response["ok"] == 1;
}
catch (Exception)
{
- throw;
+ return false;
}
- //var result = toDb.RunCommand(new CommandDocument()
- //{
- // {"cloneCollection", dbName + "." + collectionName},
- // {"from", fromDb},
- // {"copyIndexes", isIndex}
- //});
- //return result.Response.Contains("ok") && result.Response["ok"] == 1;
}
- ///
- /// 索引选项
- ///
- public struct IndexOption
- {
- public bool IsBackground;
-
- public bool IsDropDups;
-
- public bool IsSparse;
-
- public bool IsUnique;
-
- ///
- /// 是否为 Partial Indexes
- ///
- public bool IsPartial;
- public bool IsExpireData;
-
- public int Ttl;
-
- public string IndexName;
-
- public List AscendingKey;
-
- public List DescendingKey;
-
- public string GeoSpatialKey;
-
- public string FirstKey;
-
- public string TextKey;
-
- ///
- /// Partial Indexes 的条件
- ///
- public string PartialCondition;
- }
}
}
\ No newline at end of file
diff --git a/readme.md b/readme.md
index 2c9efec4..8046ec87 100644
--- a/readme.md
+++ b/readme.md
@@ -68,6 +68,7 @@ CSharp Mongo Driver 2.4.0-beta1
5. ML插件化
6. 修正了切断连接无效的问题
7. NetCore和Net版本条件编译
+8. BsonDocument树形表示优化
###聚合
1. $indexStats $stage,$sortByCount(From MongoDB3.4), $sample, $unwind
@@ -75,6 +76,9 @@ CSharp Mongo Driver 2.4.0-beta1
3. 优化聚合UI
4. 聚合结果保存为视图
+###索引管理器
+1. 更新了索引种类(7种索引)
+
###mongobooster功能的借鉴
1. 增加了MongoDB官方文档的链接
2. BsonGuidRepresentation概念的引入