GuidRepresentation in connection string for .NET driver

383 views
Skip to first unread message

DaveC

unread,
Sep 27, 2012, 9:20:39 PM9/27/12
to mongod...@googlegroups.com
Is there a connection string option to set the GuidRepresentation used in the .NET driver?  I don't see it documented anywhere, but it seems like many of the fields in MongoDatabaseSettings can be set in the connection string, so I'm wondering if I can set GuidRepresentation to Standard there as well.

Thanks.

craiggwilson

unread,
Sep 27, 2012, 9:35:16 PM9/27/12
to mongod...@googlegroups.com
Yes, you can either use the name guids or uuidrepresentation.  The value would be one of the GuidRepresentation enum values...  so

mongodb://localhost/?safe=true&uuidRepresentation=Standard

    public enum GuidRepresentation
    {
        /// <summary>
        /// The representation for Guids is unspecified, so conversion between Guids and Bson binary data is not possible.
        /// </summary>
        Unspecified = 0,
        /// <summary>
        /// Use the new standard representation for Guids (binary subtype 4 with bytes in network byte order).
        /// </summary>
        Standard,
        /// <summary>
        /// Use the representation used by older versions of the C# driver (including most community provided C# drivers).
        /// </summary>
        CSharpLegacy,
        /// <summary>
        /// Use the representation used by older versions of the Java driver.
        /// </summary>
        JavaLegacy,
        /// <summary>
        /// Use the representation used by older versions of the Python driver.
        /// </summary>
        PythonLegacy

DaveC

unread,
Sep 28, 2012, 12:43:51 PM9/28/12
to mongod...@googlegroups.com
That helps, thank you.  By the way, it seems the options should be separated by a semicolon instead of ampersand.

This works:

mongodb://localhost/?safe=true;uuidRepresentation=Standard

This doesn't:

mongodb://localhost/?safe=true&uuidRepresentation=Standard

Thanks,
Dave

Robert Stam

unread,
Sep 28, 2012, 12:51:00 PM9/28/12
to mongod...@googlegroups.com
I copy and pasted your second connection string into a test program and it worked fine for me. Semicolons and ampersands are supposed to be interchangeable.

What error message are you getting? Can you proivde a stack trace?

Robert

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

DaveC

unread,
Sep 28, 2012, 2:19:02 PM9/28/12
to mongod...@googlegroups.com
Ok, I see the problem after a closer look at the exception...if I hard code the connection string with ampersands, it works fine, but if it's in an app.config file, the ampersand needs to be URL encoded (or, well, the whole connection string needs to be).
Reply all
Reply to author
Forward
0 new messages