복붙노트

[MONGODB] MongoDB를 Linq에 거기에 "쿼리 설명"인가?

MONGODB

MongoDB를 Linq에 거기에 "쿼리 설명"인가?

.explain 실행하는 방법 () 또는 LINQ 쿼리에 해당하는 있습니까? 내가 알고 싶은 것

해결법

  1. ==============================

    1.당신은 충분히 쉽게 쿼리 래퍼가있는 경우 JSON을 얻을 수 있습니다;

    당신은 충분히 쉽게 쿼리 래퍼가있는 경우 JSON을 얻을 수 있습니다;

    var qLinq = Query<T>.Where(x => x.name=="jim");
    Console.WriteLine(qLinq.ToJson());
    

    이 작업을 수행 할 수 있도록 MongoCursor에 대한 설명 () 메소드도 있습니다;

    var exp = Collection.FindAs<T>(qLinq).Explain()
    Console.WriteLine(exp.ToJson());
    

    그래서 당신은 시간을 가지고 싶다면, "밀리"에있다;

    var msTaken = exp.First(x => x.Name == "millis").Value.AsInt32;
    

    당신이 된 IQueryable이있는 경우, 이런 식으로 뭔가를 시도;

    void Do(MongoCollection col, IQueryable iq)
    {
            // Json Mongo Query
            var imq = (iq as MongoQueryable<Blob>).GetMongoQuery();
            Console.WriteLine(imq.ToString());
    
            // you could also just do;
            // var cursor = col.FindAs(typeof(Blob), imq);
            var cursor = MongoCursor.Create(typeof(Blob), col, imq, ReadPreference.Nearest);
            var explainDoc = cursor.Explain();
    
            Console.WriteLine(explainDoc);
        }//Do()
    
  2. ==============================

    2.당신이 도서관에서이 기능을 원하는 경우에, 난 그냥 제목의 GitHub의 프로젝트를 생성

    당신이 도서관에서이 기능을 원하는 경우에, 난 그냥 제목의 GitHub의 프로젝트를 생성

    .NET 용 MongoDB의 쿼리 도우미

    https://github.com/mikeckennedy/mongodb-query-helper-for-dotnet

    그것은 것입니다 :

    그것을 확인하고 귀하가 흥미있을 경우에 기여하고 있습니다.

  3. ==============================

    3.예, 있습니다. 그것은 모든 것을 .explain가 수행하고 상세 (그것이 실행하는 데 걸린 시간을 포함)에 대한 부울을 가지고 보여줍니다

    예, 있습니다. 그것은 모든 것을 .explain가 수행하고 상세 (그것이 실행하는 데 걸린 시간을 포함)에 대한 부울을 가지고 보여줍니다

    var database = new MongoClient().GetServer().GetDatabase("db");
    var collection = database.GetCollection<Hamster>("Hamsters");
    
    var explanation = collection.AsQueryable().Where(hamster => hamster.Name == "bar").Explain(true);
    Console.WriteLine(explanation);
    

    그래도 쿼리를 표시하지 않습니다. 여기에 대한 확장 방법이다 :

    public static string GetMongoQuery<TItem>(this IQueryable<TItem> query)
    {
        var mongoQuery = query as MongoQueryable<TItem>;
        return mongoQuery == null ? null : mongoQuery.GetMongoQuery().ToString();
    }
    

    용법:

    var query = collection.AsQueryable().Where(hamster => hamster.Name == "bar").GetMongoQuery();
    Console.WriteLine(query);
    
  4. ==============================

    4.MongoDB를 3 C # 나는 다음과 같은 사용 :

    MongoDB를 3 C # 나는 다음과 같은 사용 :

    var users = Mongo.db.GetCollection<User>("Users");
    var r = users(m => m._id == yourIdHere)
        .Project(m => new { m._id, m.UserName, m.FirstName, m.LastName })
        .Limit(1);
    
    Console.WriteLine(r.ToString());
    

    결과:

    find({ "_id" : ObjectId("56030e87ca42192008ed0955") }, { "_id" : 1, "UserName" : 1, "FirstName" : 1, "LastName" : 1 }).limit(1) 
    
  5. from https://stackoverflow.com/questions/13254784/is-there-an-explain-query-for-mongodb-linq by cc-by-sa and MIT license