Ich brauche den Wert von _id und Boss_id von ObjectId
zu string
für alle Dokument in einer mongodb Sammlung deserialisieren C# .Netdeserialisieren mehr BSON ObjectID zu String eines MongoDB Dokuments in C# .Net
Meine Sammlung Employee
mit (hier klebte ich nur 2 Dokumente in Echt ich habe mehr als 10K Dokumente)
{
"_id" : ObjectId("575845a713d284da0ac2ee81"),
"Boss_id" : ObjectId("575841b313d284da0ac2ee7d"),
"Emp_Name" : "Raj",
}
{
"_id" : ObjectId("575845d213d284da0ac2ee82"),
"Boss_id" : ObjectId("575841b313d284da0ac2ee7d"),
"Emp_Name" : "Kumar"
}
Mein C# Quelle - Model-Klasse EmployeeModel
public class EmployeeModel
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Boss_Id { get; set; }
public string Emp_Name { get; set; }
}
Mein C# MongoDB Code:
private static IMongoClient _client;
private static IMongoDatabase _database;
_client = new MongoClient();
_database = _client.GetDatabase("RMS");
var collection = _database.GetCollection<EmployeeModel>("Employee");
BsonDocument temp = new BsonDocument("Emp_Name", "Raj");
var cItem = collection.Find(temp).ToList();
if ((cItem != null) && (cItem.Count > 0))
{
_EmpList = cItem;
}
Seine Wurf Ausnahme
Attribute des Typs MongoDB.Bson.Serialization .Attributes.BsonIdAttribute kann nurseinangewendet auf ein einzelnes Mitglied.
bitte helfen Sie mir, wie Sie die Dokumente holen?
Ich denke, der Fehler versucht, Ihnen zu sagen, dass Sie nicht mehr als 2 Felder als BsonType.ObjectId verwenden können – KRONWALLED