Unable to create compound index with C# driver

293 views
Skip to first unread message

Gavin

unread,
Jul 2, 2011, 6:53:03 AM7/2/11
to mongodb-user
Hi,

I have a document with a structure similair to the following:

"s": {
"a": 16,
"sc": 1,
"g": 'M'
}

I am trying to create an index on the individual fields like "a", "sc"
and "g". In the shell I can do something like
db.mycoll.ensureIndex( { "s.a" : 1, "s.sc" : 1, "s.g" : 1 }) and it
works fine (although I'm not sure if this is how I am supposed to be
doing it).

If I try this in the driver
using ...GetCollection("mycoll").EnsureIndex("s.a", "s,sc", "s.g"); I
get a BsonSerializationException "Element name 's.sc' is not valid
because it contains a '.'

Is there a reason why the driver is carrying out this validation in
this instance (as the syntax is indeed valid according to the official
documentation - see compound indexes here
http://www.mongodb.org/display/DOCS/Indexes#Indexes-DocumentsasKeys)?
Is there an alternative to creating these indexes using the driver?

Cheers!

Gav

Nat

unread,
Jul 2, 2011, 9:40:27 AM7/2/11
to mongod...@googlegroups.com
use driver version 1.1.0.4184 instead. The one from head has a side effect from https://jira.mongodb.org/browse/CSHARP-253

Robert Stam

unread,
Jul 3, 2011, 7:27:44 PM7/3/11
to mongodb-user
I've reopened https://jira.mongodb.org/browse/CSHARP-253.

The implementation of CSHARP-253 will have to be modified to take this
into account.

Robert Stam

unread,
Jul 4, 2011, 11:57:36 AM7/4/11
to mongodb-user
Just committed a further change to the master branch to allow creation
of indexes on nested element names.

This was the JIRA comment:

Further work on CSHARP-253 to allow CreateIndex to work with nested
element names. CreateIndex calls Insert, so Insert has been modified
to allow the caller to set CheckElementNames to false (see the new
MongoInsertOptions class). While this was put in for CreateIndex, it
also makes it possible for a developer to disable element name
checking if necessary.


On Jul 3, 7:27 pm, Robert Stam <rstam10...@gmail.com> wrote:
> I've reopenedhttps://jira.mongodb.org/browse/CSHARP-253.
Reply all
Reply to author
Forward
0 new messages