2016-10-12 1 views
0

오늘 저는 SQL Ce에서 MongoDB로 옮기고 싶었습니다. 드라이버를 다운로드하고 서버를 로컬 PC에서 실행했습니다.아마도 MongoDB의 비정상적인 오류입니까?

가 여기 내 실제 코드입니다 (BTW 나는 심지어 MongoCollection에 IMongoCollection 캐스팅하는 것이 안전 알고하지 않습니다) : 처리되지 않은를 :

using System; 
using MongoDB.Driver; 

namespace MongoShit 
{ 
    class Program 
    { 
     class Apple 
     { 
      public int price, weight; 
      public string color; 

      public Apple() 
      { 
       price = 0; 
       weight = 0; 
       color = "ayye"; 
      } 
     } 

     static protected IMongoClient client; 
     static protected IMongoDatabase database; 

     static void Main(string[] args) 
     { 
      client = new MongoClient("mongodb://localhost"); 
      database = client.GetDatabase("test"); 

      database.CreateCollection("apples"); 

      var data = new Apple() { price = 100, weight = 500, color = "green" }; 

      MongoCollection<Apple> collection = (MongoCollection<Apple>)database.GetCollection<Apple>("apples"); 
      collection.Insert(data); 

      var cursor = collection.FindAll(); 
      foreach(Apple a in cursor) 
      { 
       Console.WriteLine(string.Format("Apple, P: {0} W: {1} C: {2}", new object[] { a.price, a.weight, a.color })); 
      } 
      Console.Read(); 
     } 
    } 
} 

을하지만, 나는 다음과 같은 오류가 프로그램을 실행하려고 할 때마다 유형 'System.IO.FileNotFoundException'의 예외가 mscorlib.dll에서

추가 정보 발생 : 파일이나 어셈블리를로드 할 수 없습니다 'System.Runtime.InteropServices.RuntimeInformation, 버전 = 4.0.0.0을, 문화 = 중립, PublicKeyToken = b03f5f7f11d50a3a '또는 그 의존성 중 하나. 시스템이 지정된 파일을 찾을 수 없습니다.

무슨 일 이니? : 당신은 MongoCollection에 캐스트 할 필요가없는 S

답변

0

또한

var collection = database.GetCollection<Apple>("apples"); 

, 당신이 아직 존재하지 않는 경우, MongoDB가이 작업을 수행 할 명시 적으로 컬렉션을 만들 필요가 없습니다에 대한 때문에이 라인은 작동합니다 ,이 줄은 갈 수 있습니다

0

Mongo 2.4의 NuGet 패키지에는 문제가 있습니다. 종속성이 없습니다. 그것은 10 월 26 일에 수정되었지만 아직 NuGet에서는 수정되지 않았습니다.

2.3을 사용하거나 업데이트가 푸시 될 때까지 종속성을 수동으로 추가 할 수 있습니다.