[CSharpDriver] problems using the MongoCollection.Save method with a composite key

206 views
Skip to first unread message

Michael

unread,
Apr 11, 2011, 2:32:42 PM4/11/11
to mongodb-user
Hi all,

I'm trying to use the MongoDB CSharpDriver with a POCO holding a
composite key.
But I've got problems using the MongoCollection.Save method...
This is a sample :

namespace MongodbTest
{
class Id
{
public int AccountId { get; set; }
public int Index { get; set; }
}

class Foo
{
[BsonId]
public Id Id;
public string name;
}


class Program
{
static void Main(string[] args)
{
MongoServer server = MongoServer.Create("mongodb://
localhost");

MongoDatabase test = server.GetDatabase("test");
MongoCollection<Foo> foos =
test.GetCollection<Foo>("foos");

Foo newFoo = new Foo { Id = new Id { AccountId = 1, Index
= 1 }, name = "foo1-1" };

// will throw an ArgumentException ".NET type
MongodbTest.Id cannot be mapped to a BsonValue"
foos.Save(newFoo);

// will work with no pb
foos.Update(QueryWrapper.Create(new { _id = newFoo.Id }),
UpdateWrapper.Create<Foo>(newFoo), UpdateFlags.Upsert);

// will work with no pb
Foo foo = foos.FindOne(QueryWrapper.Create(new { _id =
newFoo.Id }));
}
}
}

Thank you,

Michael

Robert Stam

unread,
Apr 11, 2011, 2:37:28 PM4/11/11
to mongodb-user
I will try to reproduce and report back.

Robert Stam

unread,
Apr 11, 2011, 2:52:39 PM4/11/11
to mongodb-user
I am able to reproduce this (thanks for the good sample code!) and
have created a JIRA ticket for this:

https://jira.mongodb.org/browse/CSHARP-198

Thanks for reporting this.

Robert
Reply all
Reply to author
Forward
0 new messages