Java로 Mongo DB를 사용하고 있습니다.Mongo DB Cursor에서 정보 얻기
아래 그림과 같이 Mongo DB에 주어진 String이있는 Symbol이 있는지 확인하려고합니다. 이 작업은 가능하지만 문제는 MOngo DB를 두 번 호출하는 것이므로 매우 비쌉니다 . 하나의 호출로 줄이고 더 많은 성능 지향적으로 만들 수있는 방법이 있습니까?
이 내 코드
public class Test
{
public static void main(String args[])
{
DBCursor cursor = null;
DBCollection coll = null;
BasicDBObject query = new BasicDBObject();
String symbol = args[0];
query.put("symbol", "" + symbol);
cursor = coll.find(query);
int count = coll.find(query).count();
/* Here is want to avoid the count call , is there anyway by which
the cursor the obtained cursor tells , that there exists the symbol
in Mongo DB */
if(count>=1)
{
// If found then do
if (cursor != null) {
}
}
else
{
// If Not found then do
}
}
}
감사 Rohit, 당신은) (즉 cursor.count 말을 의미하는 단계; 다른 데이터베이스 호출을하지 않겠습니까 ?? 내가 맞습니까? – Pawan
@PreethiJain .. 네, 맞습니다. 다른 전화를하지 않습니다. Cursor는 JDBC의 ResultSet과 같습니다. 커서를 앞으로 이동하여 각 레코드에 액세스 할 수 있으므로 쿼리에서 반환 된 전체 결과가 고갈됩니다. –
고마워요. – Pawan