protected void EnsureIndex(string name, object keys, object extraOptions = null)
        {
            if (!Collection.IndexExistsByName(name))
            {
                IMongoIndexKeys indexKeys = new IndexKeysWrapper(keys);
                var             ints      = keys as Dictionary <string, int>;
                if (ints != null)
                {
                    indexKeys = new IndexKeysDocument(ints);
                }


                var options = new Dictionary <string, object>
                {
                    { "name", name },
                    { "background", true }
                };

                if (extraOptions != null)
                {
                    foreach (var option in extraOptions.ToDictionary())
                    {
                        options.Add(option.Key, option.Value);
                    }
                }

                Collection.EnsureIndex(indexKeys, new IndexOptionsDocument(options));
            }
        }
Example #2
0
        public void TestSerializeIndexKeysWrapped()
        {
            var c = new C {
                X = 1
            };
            var w        = IndexKeysWrapper.Create(c);
            var json     = w.ToJson();
            var expected = "{ 'X' : 1 }".Replace("'", "\"");

            Assert.Equal(expected, json);
        }