2017-10-16 1 views
0

다음과 같이 mongodb 데이터베이스를 쿼리하여 문서를 찾습니다.값이 C# 드라이버를 사용하여 mongodb 데이터베이스에 있는지 확인하십시오. 2.4.4

 var collection = _database.GetCollection<BsonDocument>("knowledge"); 
     var builder = Builders<BsonDocument>.Filter; 
     var filter = builder.Regex("question", "(account)") & builder.Regex("question", "(open)"); 
     var results = await collection.Find(filter).ToListAsync(); 

질문을 찾으면 콘솔에 표시합니다. 아무 것도 발견되지 않으면 '아무것도 찾지 못했습니다'라고 표시하고 싶습니다. 여기 어떻게 확인하나요?

나는
if(results == null) 

와`

if (builder.Exists("question", false)) 

http://www.fourthbottle.com/2016/08/not-exists-in-mongodb-with-dotnet-driver.html

결과 List<BsonDocument> 유형에 시도. 드라이버 버전 2.4.4를 사용하고 있습니다.

답변

1

결과 변수가 목록입니다. 결과가 필요합니다. 계산 == 0 확인.

관련 문제