Inheritance: BuilderBase, IMongoIndexOptions
        /// <summary>
        /// 增加索引
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdAddIndex_Click(object sender, EventArgs e)
        {
            List<String> AscendingKey = new List<String>();
            List<String> DescendingKey = new List<String>();

            for (int i = 0; i < 5; i++)
            {
                ctlIndexCreate ctl = (ctlIndexCreate)Controls.Find("ctlIndexCreate" + (i + 1).ToString(), true)[0];
                if (ctl.KeyName != String.Empty)
                {
                    if (ctl.IsAscendingKey)
                    {
                        AscendingKey.Add(ctl.KeyName);
                    }
                    else
                    {
                        DescendingKey.Add(ctl.KeyName);
                    }
                }
            }
            IndexOptionsBuilder option = new IndexOptionsBuilder();
            option.SetBackground(chkIsBackground.Checked);
            option.SetDropDups(chkIsDroppedDups.Checked);
            option.SetSparse(chkIsSparse.Checked);
            option.SetUnique(chkIsUnique.Checked);
            if (txtIndexName.Text != String.Empty && !SystemManager.GetCurrentCollection().IndexExists(txtIndexName.Text))
            {
                option.SetName(txtIndexName.Text);
            }
            MongoDBHelper.CreateMongoIndex(AscendingKey.ToArray(), DescendingKey.ToArray(), option);
            RefreshList();
            MessageBox.Show("Index Add Completed!");
        }
        /// <summary>
        /// Initializes all the needed indexes for the pages to optimize search on them.
        /// </summary>
        public void InitializeIndexes()
        {
            // key options
            var options = new IndexOptionsBuilder().SetUnique(true);

            // page search key
            //var keys = new IndexKeysBuilder().Ascending("Spot");
            //Spots.EnsureIndex(keys, options);

            // general page search
            var keys = new IndexKeysBuilder().Ascending("_id");
            Spots.EnsureIndex(keys, options);

            options.SetUnique(false);

            keys = new IndexKeysBuilder().Ascending("PhaseID");
            Spots.EnsureIndex(keys, options);
        }
Example #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="uiOption"></param>
 /// <param name="strMessageTitle"></param>
 /// <param name="strMessageContent"></param>
 /// <returns></returns>
 public static bool CreateIndex(IndexOption uiOption, 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)
     {
         IMongoQuery query = (QueryDocument) BsonDocument.Parse(uiOption.PartialCondition);
         option.SetPartialFilterExpression(query);
     }
     if (uiOption.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)
         {
             strMessageTitle = "Can't Set TTL";
             strMessageContent = "the TTL index may not be compound (may not have multiple fields).";
             canUseTtl = false;
         }
         else
         {
             //不能是_id
             if (uiOption.FirstKey == ConstMgr.KeyId)
             {
                 strMessageTitle = "Can't Set TTL";
                 strMessageContent =
                     "you cannot create this index on the _id field, or a field that already has an index.";
                 canUseTtl = false;
             }
         }
         if (RuntimeMongoDbContext.GetCurrentCollection().IsCapped())
         {
             strMessageTitle = "Can't Set TTL";
             strMessageContent =
                 "you cannot use a TTL index on a capped collection, because MongoDB cannot remove documents from a capped collection.";
             canUseTtl = false;
         }
         if (canUseTtl)
         {
             strMessageTitle = "Constraints Of TimeToLive";
             strMessageContent =
                 "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));
         }
     }
     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)
     {
         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;
         }
     }
     else
     {
         strMessageTitle = "Index Add Failed!";
         strMessageContent = "Please Check the index information.";
         result = false;
     }
     return result;
 }
 /// <summary>
 ///     增加索引
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdAddIndex_Click(object sender, EventArgs e)
 {
     var AscendingKey = new List<String>();
     var DescendingKey = new List<String>();
     String GeoSpatialKey = string.Empty;
     String FirstKey = string.Empty;
     String TextKey = String.Empty;
     for (int i = 0; i < 5; i++)
     {
         var ctl = (ctlIndexCreate) Controls.Find("ctlIndexCreate" + (i + 1), true)[0];
         if (ctl.KeyName == String.Empty) continue;
         FirstKey = ctl.KeyName.Trim();
         switch (ctl.IndexKeyType)
         {
             case MongoDbHelper.IndexType.Ascending:
                 AscendingKey.Add(ctl.KeyName.Trim());
                 break;
             case MongoDbHelper.IndexType.Descending:
                 DescendingKey.Add(ctl.KeyName.Trim());
                 break;
             case MongoDbHelper.IndexType.GeoSpatial:
                 GeoSpatialKey = ctl.KeyName.Trim();
                 break;
             case MongoDbHelper.IndexType.Text:
                 TextKey = ctl.KeyName.Trim();
                 break;
             default:
                 break;
         }
     }
     var option = new IndexOptionsBuilder();
     option.SetBackground(chkIsBackground.Checked);
     option.SetDropDups(chkIsDroppedDups.Checked);
     option.SetSparse(chkIsSparse.Checked);
     option.SetUnique(chkIsUnique.Checked);
     if (chkExpireData.Checked)
     {
         //TTL的限制条件很多
         //http://docs.mongodb.org/manual/tutorial/expire-data/
         //不能是组合键
         Boolean CanUseTTL = true;
         if ((AscendingKey.Count + DescendingKey.Count + (String.IsNullOrEmpty(GeoSpatialKey) ? 0 : 1)) != 1)
         {
             MyMessageBox.ShowMessage("Can't Set TTL",
                 "the TTL index may not be compound (may not have multiple fields).");
             CanUseTTL = false;
         }
         else
         {
             //不能是_id
             if (FirstKey == MongoDbHelper.KEY_ID)
             {
                 MyMessageBox.ShowMessage("Can't Set TTL",
                     "you cannot create this index on the _id field, or a field that already has an index.");
                 CanUseTTL = false;
             }
         }
         if (SystemManager.GetCurrentCollection().IsCapped())
         {
             MyMessageBox.ShowMessage("Can't Set TTL",
                 "you cannot use a TTL index on a capped collection, because MongoDB cannot remove documents from a capped collection.");
             CanUseTTL = false;
         }
         if (CanUseTTL)
         {
             MyMessageBox.ShowMessage("Constraints", "Constraints Of TimeToLive",
                 "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.",
                 true);
             option.SetTimeToLive(new TimeSpan(0, 0, (int) numTTL.Value));
         }
     }
     if (txtIndexName.Text != String.Empty &&
         !SystemManager.GetCurrentCollection().IndexExists(txtIndexName.Text) &&
         (AscendingKey.Count + DescendingKey.Count +
          (String.IsNullOrEmpty(GeoSpatialKey) ? 0 : 1) +
          (String.IsNullOrEmpty(TextKey) ? 0 : 1)) != 0)
     {
         option.SetName(txtIndexName.Text);
         try
         {
             //暂时要求只能一个TextKey
             if (!string.IsNullOrEmpty(TextKey))
             {
                 var TextKeysDoc = new IndexKeysDocument {{TextKey, "text"}};
                 SystemManager.GetCurrentCollection().CreateIndex(TextKeysDoc, option);
             }
             else
             {
                 MongoDbHelper.CreateMongoIndex(AscendingKey.ToArray(), DescendingKey.ToArray(), GeoSpatialKey,
                     option);
             }
             MyMessageBox.ShowMessage("Index Add Completed!",
                 "IndexName:" + txtIndexName.Text + " is add to collection.");
         }
         catch (Exception ex)
         {
             SystemManager.ExceptionDeal(ex, "Index Add Failed!", "IndexName:" + txtIndexName.Text);
         }
         RefreshList();
     }
     else
     {
         MyMessageBox.ShowMessage("Index Add Failed!", "Please Check the index information.");
     }
 }
        private void CreateUserCardIndexes()
        {
            var keys = new IndexKeysBuilder();

            keys.Ascending("PlaneswalkerId","MultiverseId");

            var options = new IndexOptionsBuilder();
            options.SetSparse(true);
            options.SetUnique(true);

            var collection = database.GetCollection<UserCard>("user_cards");

            collection.EnsureIndex(keys, options);
        }
Example #6
0
 /// <summary>
 ///     添加索引
 /// </summary>
 /// <param name="ascendingKey"></param>
 /// <param name="descendingKey"></param>
 /// <param name="geoSpatialKey"></param>
 /// <param name="option"></param>
 /// <param name="currentCollection"></param>
 /// <returns></returns>
 public static bool CreateMongoIndex(string[] ascendingKey, string[] descendingKey, string geoSpatialKey,
     IndexOptionsBuilder option, MongoCollection currentCollection)
 {
     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;
 }
Example #7
0
        /// <summary>
        /// 创建索引
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="v"></param>
        private void CreateIndex(MongoCollection collection, Variant v)
        {
            var indexs = collection.GetIndexes();
            HashSet<string> hs = new HashSet<string>();
            foreach (IndexInfo index in indexs)
            {
                hs.Add(index.Name);
            }
            foreach (var item in v)
            {
                string indexName = item.Key;
                Variant keys = item.Value as Variant;
                if (keys != null)
                {
                    IndexOptionsBuilder indexOpt = new IndexOptionsBuilder();
                    indexOpt.SetName(indexName);
                    if (keys.ContainsKey("dropDups"))
                    {
                        if (keys["dropDups"] is bool)
                        {
                            indexOpt.SetDropDups((bool)keys["dropDups"]);
                        }
                        keys.Remove("dropDups");
                    }

                    if (keys.ContainsKey("background"))
                    {
                        if (keys["background"] is bool)
                        {
                            indexOpt.SetBackground((bool)keys["background"]);
                        }
                        keys.Remove("background");
                    }

                    if (keys.ContainsKey("unique"))
                    {
                        if (keys["unique"] is bool)
                        {
                            indexOpt.SetUnique((bool)keys["unique"]);
                        }
                        keys.Remove("unique");
                    }

                    if (keys.ContainsKey("sparse"))
                    {
                        if (keys["sparse"] is bool)
                        {
                            indexOpt.SetSparse((bool)keys["sparse"]);
                        }
                        keys.Remove("sparse");
                    }

                    bool find = false;
                    IndexKeysBuilder indexKey = new IndexKeysBuilder();
                    foreach (var dsa in keys)
                    {
                        string ckey = dsa.Key;
                        if (ckey != string.Empty && dsa.Value is int)
                        {
                            int dec = (int)dsa.Value;
                            if (dec == 1)
                            {
                                indexKey.Ascending(ckey);
                                find = true;
                            }
                            else if (dec == -1)
                            {
                                indexKey.Descending(ckey);
                                find = true;
                            }
                        }
                    }
                    if (find)
                    {
                        if (!hs.Contains(indexName))
                            collection.CreateIndex(indexKey, indexOpt);
                    }
                    else
                    {
                        if (hs.Contains(indexName))
                            collection.DropIndexByName(indexName);
                    }
                }
            }
        }
        private void CreateChangeRequestIndexes()
        {
            var keys = new IndexKeysBuilder();

            keys.Ascending("Id");

            var options = new IndexOptionsBuilder();
            options.SetSparse(true);
            options.SetUnique(true);

            var collection = database.GetCollection<CardChange>("card_changes");

            collection.EnsureIndex(keys, options);
        }
 /// <summary>
 /// 添加索引
 /// </summary>
 /// <param name="AscendingKey"></param>
 /// <param name="DescendingKey"></param>
 /// <param name="IsBackground"></param>
 /// <param name="IsDropDups"></param>
 /// <param name="IsSparse"></param>
 /// <param name="IsUnique"></param>
 /// <param name="IndexName"></param>
 /// <returns></returns>
 public static Boolean CreateMongoIndex(String[] AscendingKey, String[] DescendingKey,
     Boolean IsBackground = false, Boolean IsDropDups = false, Boolean IsSparse = false, Boolean IsUnique = false, String IndexName = "")
 {
     MongoCollection mongoCol = SystemManager.GetCurrentCollection();
     IndexKeysBuilder indexkeys = new IndexKeysBuilder();
     indexkeys.Ascending(AscendingKey);
     indexkeys.Descending(DescendingKey);
     IndexOptionsBuilder option = new IndexOptionsBuilder();
     option.SetBackground(IsBackground);
     option.SetDropDups(IsDropDups);
     option.SetSparse(IsSparse);
     option.SetUnique(IsUnique);
     if (IndexName != String.Empty && !mongoCol.IndexExists(IndexName))
     {
         option.SetName(IndexName);
     }
     mongoCol.CreateIndex(indexkeys, option);
     return true;
 }
Example #10
0
        /// <summary>
        /// Initializes all the needed indexes for the pages to optimize search on them.
        /// </summary>
        public void InitializeIndexes()
        {
            // key options
            var options = new IndexOptionsBuilder().SetUnique(true);

            // page search key
            var keys = new IndexKeysBuilder().Ascending("ParcelName");
            Parcels.EnsureIndex(keys, options);

            // general page search
            keys = new IndexKeysBuilder().Ascending("_id");
            Parcels.EnsureIndex(keys, options);
        }
 /// <summary>
 ///     添加索引
 /// </summary>
 /// <param name="AscendingKey"></param>
 /// <param name="DescendingKey"></param>
 /// <param name="option"></param>
 /// <returns></returns>
 public static Boolean CreateMongoIndex(String[] AscendingKey, String[] DescendingKey, String GeoSpatialKey,
     IndexOptionsBuilder option)
 {
     MongoCollection mongoCol = SystemManager.GetCurrentCollection();
     var indexkeys = new IndexKeysBuilder();
     if (!String.IsNullOrEmpty(GeoSpatialKey))
     {
         indexkeys.GeoSpatial(GeoSpatialKey);
     }
     indexkeys.Ascending(AscendingKey);
     indexkeys.Descending(DescendingKey);
     mongoCol.CreateIndex(indexkeys, option);
     return true;
 }
 /// <summary>
 /// 添加索引
 /// </summary>
 /// <param name="AscendingKey"></param>
 /// <param name="DescendingKey"></param>
 /// <param name="option"></param>
 /// <returns></returns>
 public static Boolean CreateMongoIndex(String[] AscendingKey, String[] DescendingKey, IndexOptionsBuilder option)
 {
     MongoCollection mongoCol = SystemManager.GetCurrentCollection();
     IndexKeysBuilder indexkeys = new IndexKeysBuilder();
     indexkeys.Ascending(AscendingKey);
     indexkeys.Descending(DescendingKey);
     mongoCol.CreateIndex(indexkeys, option);
     return true;
 }
        public void DoCreateIndexes(OperationStatus operation, ConnectionInfo cnn, string database, string collection, IEnumerable<IndexDescriptor> indexes)
        {
            var col = MongoUtilities.Create(cnn).GetDatabase(database).GetCollection(collection);

            try
            {
                col.DropAllIndexes();
            }
            catch (Exception ex)
            {
                Utilities.LogException(ex);
            }

            var count = 0;
            var errors = new List<string>();
            foreach (var index in indexes)
            {
                operation.PercentComplete = (int) ((100.0 / (double)indexes.Count()) * (double) count);
                operation.Description = string.Format(Properties.Resources.ManageIndexes_Creating, ++count);

                try
                {
                    var keys = new IndexKeysBuilder();

                    foreach (var property in index.IndexedProperties)
                    {
                        switch (property.IndexType)
                        {
                            case IndexType.Descending:
                                keys.Descending(property.PropertyName);
                                break;
                            case IndexType.Geospatial:
                                keys.GeoSpatial(property.PropertyName);
                                break;
                            default:
                                keys.Ascending(property.PropertyName);
                                break;
                        }
                    }

                    var options = new IndexOptionsBuilder();
                    options.SetSparse(index.IsSparse);
                    options.SetUnique(index.IsUnique);

                    col.CreateIndex(keys, options);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("2d has to be first"))
                    {
                        errors.Add(string.Format(Properties.Resources.ManageIndexes_GeospatialNotFirst, count));
                    }
                    else if (ex.Message.Contains("geo field") || ex.Message.Contains("location object expected"))
                    {
                        errors.Add(string.Format(Properties.Resources.ManageIndexes_InvalidGeospatial, count));
                    }
                    else if (ex.Message.Contains("duplicate key"))
                    {
                        errors.Add(string.Format(Properties.Resources.ManageIndexes_InvalidUnique, count));
                    }
                    else
                    {
                        errors.Add(string.Format(Properties.Resources.ManageIndexes_UnknownError, count, ex.Message));
                        Utilities.LogException(ex);
                    }
                }
            }

            operation.IsComplete = true;
            if (errors.Count == 0)
            {
                operation.IsSuccess = true;
                operation.Description = string.Format(Properties.Resources.ManageIndexes_Success, indexes.Count());
            }
            else
            {
                operation.IsSuccess = false;
                var errorString = new StringBuilder();
                errors.ToList().ForEach(
                    error =>
                    {
                        errorString.Append("\n");
                        errorString.Append(error);
                    });
                operation.Description = string.Format(Properties.Resources.ManageIndexes_Fail, errors.Count, errorString);
            }
        }
Example #14
0
        /// <summary>
        /// </summary>
        /// <param name="KeyOptions"></param>
        /// <param name="strMessageTitle"></param>
        /// <param name="strMessageContent"></param>
        /// <returns></returns>
        public static bool CreateIndex(IndexOption KeyOptions, ref string strMessageTitle, ref string strMessageContent)
        {
            var option = new IndexOptionsBuilder();
            option.SetBackground(KeyOptions.IsBackground);
            option.SetDropDups(KeyOptions.IsDropDups);
            option.SetSparse(KeyOptions.IsSparse);
            option.SetUnique(KeyOptions.IsUnique);
            if (KeyOptions.IsPartial)
            {
                IMongoQuery query = (QueryDocument)BsonDocument.Parse(KeyOptions.PartialCondition);
                option.SetPartialFilterExpression(query);
            }
            if (KeyOptions.IsExpireData)
            {
                //TTL的限制条件很多
                //http://docs.mongodb.org/manual/tutorial/expire-data/
                //不能是组合键
                var canUseTtl = true;
                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).";
                    canUseTtl = false;
                }
                else
                {
                    //不能是_id
                    if (KeyOptions.FirstKey == ConstMgr.KeyId)
                    {
                        strMessageTitle = "Can't Set TTL";
                        strMessageContent =
                            "you cannot create this index on the _id field, or a field that already has an index.";
                        canUseTtl = false;
                    }
                }
                if (RuntimeMongoDbContext.GetCurrentCollection().IsCapped())
                {
                    strMessageTitle = "Can't Set TTL";
                    strMessageContent =
                        "you cannot use a TTL index on a capped collection, because MongoDB cannot remove documents from a capped collection.";
                    canUseTtl = false;
                }
                if (canUseTtl)
                {
                    strMessageTitle = "Constraints Of TimeToLive";
                    strMessageContent =
                        "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, KeyOptions.Ttl));
                }
            }
            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;
            totalIndex += string.IsNullOrEmpty(KeyOptions.HashedKey) ? 0 : 1;

            if (string.IsNullOrEmpty(KeyOptions.IndexName) || totalIndex == 0 ||
                RuntimeMongoDbContext.GetCurrentCollection().IndexExists(KeyOptions.IndexName))
            {
                strMessageTitle = "Index Add Failed!";
                strMessageContent = "Please Check the index information.";
                return false;
            }
            option.SetName(KeyOptions.IndexName);
            string errorMessage = string.Empty;
            if (CreateMongoIndex(KeyOptions, option, RuntimeMongoDbContext.GetCurrentCollection(), ref errorMessage))
            {
                strMessageTitle = "Index Add Completed!";
                strMessageContent = "IndexName:" + KeyOptions.IndexName + " is add to collection.";
                return true;
            }
            else
            {
                strMessageTitle = "Index Add Failed!";
                strMessageContent = errorMessage;
                return false;
            }
        }
Example #15
0
 /// <summary>
 ///     添加索引
 /// </summary>
 /// <param name="IdxOpt"></param>
 /// <param name="option"></param>
 /// <param name="currentCollection"></param>
 /// <returns></returns>
 public static bool CreateMongoIndex(IndexOption IdxOpt,
     IndexOptionsBuilder option, MongoCollection currentCollection,ref string errorMessage)
 {
     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);
     if (!string.IsNullOrEmpty(IdxOpt.HashedKey)) indexkeys.Hashed(IdxOpt.HashedKey);
     indexkeys.Ascending(IdxOpt.AscendingKey.ToArray());
     indexkeys.Descending(IdxOpt.DescendingKey.ToArray());
     indexkeys.Text(IdxOpt.TextKey.ToArray());
     //CreateIndex失败的时候会出现异常!
     try
     {
         var result = mongoCol.CreateIndex(indexkeys, option);
         return result.Response.GetElement("ok").Value.AsInt32 == 1;
     }
     catch (Exception ex)
     {
         errorMessage = ex.ToString();
         return false;
     }
 }