MongoVue and Guid
I would like to insert a Guid using the mongoVue tool, how can I do it ?
To explain the context, I used to copy the json of my collection (thanks to Text View tab) and paste it in my txt file instead of using mongodump. But when I create a new collection and paste it the json from previous copy, my guid binary type is now appeared as an ""object Id"", then the problem is: I can't map in my C# code the Object ID to my Guid field. Thats why I'd like to know if it's possible to insert a guid in MongoVue.
开发者_如何学PythonThanks guys. John
You can use the following notation to enter GUIDs in MongoVUE:
{
guid_field: new Guid("3bed978a-dc87-4fa4-8a1a-f0679387fa7e")
}
To insert a new Guid (Guid.NewGuid()), you may enter:
{
guid_field: new Guid()
}
All guids are converted to Binary type-3 values.
Not sure it can answer your question, but this post can help: http://www.mongovue.com/2010/09/13/using-objectids/
When I insert an instance of the following class:
public class C {
public Guid Id;
public int X;
}
It looks like this in MongoVUE Text View:
/* 0 */
{
"_id": {
"$binary": "q4TTjt8k4UyaJI6FwuZ1EQ==",
"$type": "03"
},
"X": 1
}
Where the GUID has been represented as BSON binary value of sub type 3, which is NOT an ObjectId.
To insert a GUID in MongoVUE you would have to create a BSON binary value of sub type 3. The hard part is figuring out the Base64 value to use.
In addition, there is an issue with the storage of UUIDs in general in MongoDB. The three drivers (C#, Java and Python) that currently support UUIDs have in the past used different byte orders for the binary representation of the UUID, which makes life really hard.
Future versions of the drivers will use a new binary sub type 4 for UUIDs and will all standardize on the official UUID network byte order (the 16 bytes are stored in the same order as they appear in the string representation of the UUID).
The current version of the C# driver (version 1.1 was just released) has some experimental support for dealing with different GUID representations (see the GuidRepresentation enum and where it is used).
精彩评论