2016-08-25 4 views
1

MogoDB 문서에서 특정 문자열 개체에 문자열 배열을 일치시켜 mongoDB에서 검색 결과를 얻으려고합니다. 내 샘플 MongoDb 문서.MongoDB에서 배열에 문자열 일치

"Notedisp" : { 
    "NoteID" : NumberLong(100281), 
    "NoteTitle" : null, 
    "NoteContent" : "In mathematics, the Pythagorean theorem theorem, also known as Pythagoras's theorem, is a relation in Euclidean geometry among the three sides of a right triangle. It states that the square of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides. The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the \"Pythagorean equation\"\r\n\r\na^2 + b^2 = c^2 ,\r\nwhere c represents the length of the hypotenuse and a and b the lengths of the triangle's other two sides.",  
}, 

이미 다음 코드를 시도했습니다. 위의 코드 "Notedisp.NoteContent"에서

var listTearm = ["what","is","Pythagorean","theorem"] 
var filter = (builder.AnyIn("Notedisp.NoteContent", listTearm) 

는 MongoDB의 문서에서 문자열 개체이며 빈 문자열을 반환합니다. 그래서 특정 문자열을 MogoDb 문서와 일치시킬 수 있고 특정 데이터를 반환 할 수있는 특정 방법이 있습니다.

:

IndexKeysDefinition<Note> keys = "{ content: \"text\" }"; 
    string contentTextSearchIndex = await _collection.Indexes.CreateOneAsync(keys); 

는 다음 $text 연산자 검색어와 일치 : 단순화 된 객체와

+0

아마도 올바른 방향으로 오게 될까요? https://docs.mongodb.com/manual/reference/operator/query/text/#match-any-of-the-search-terms – dyouberg

답변

0

,

public class Note 
{ 
    [BsonId] public long Id { get; set; } 
    [BsonElement("content")] public string Content { get; set; } 
} 

먼저 당신은 당신의 컬렉션 텍스트 인덱스를 생성해야

var fdb = Builders<Note>.Filter; 
var cursor = await _collection.FindAsync(fdb.Text("what is Pythagorean theorem")); 
var docs = await cursor.ToListAsync();