我正在使用 mongodb 2.0.5 版本。尝试从 c# 连接 mongodb。将数据插入到 monogdb 工作正常。
但我想从 mongodb 检索数据并显示给用户。问题是文档属性没有进入智能感知。下面是我的代码:
namespace mongoTest
{
public class dbsDani
{
public ObjectId Id { get; set; }
public string Emp_name { get; set; }
}
class Program
{
static void Main(string[] args)
{
#region connectionTried
MongoServer server;
String con = "mongodb://192.168.71.241/?safe=true";
server = MongoServer.Create(con);
server.Connect();
if (server.State == MongoServerState.Connected)
{
//server.Connect();
Console.WriteLine("Success");
//MongoCredentials credentials = new MongoCredentials("danny", "levay");
var dbseName = server.GetDatabase("danny");
var collectionName = dbseName.GetCollection<dbsDani>("dani");
var emp = new dbsDani { Emp_name = "Jack" };
collectionName.Insert(emp);
var id = emp.Id;
var display = collectionName.FindAll().documents(); //FindAll().Documents is not coming
foreach (var document in display)
{
Console.WriteLine(document["Emp_name"]);
Console.ReadLine();
}
}
}
}