이것도 결국엔 bson 이용 방법이 문제인데
정말 bson 이 익숙해지면 mongodb 사용은 거의 끝이 날 것 같네요..
정말 bson 이 익숙해지면 mongodb 사용은 거의 끝이 날 것 같네요..
void mongo_bson_test_time_t( mongo& m )
{
// > db.foo.find()
// { "_id" : ObjectId("4f26266439584a7aa0bfce4e"),
// "time" : ISODate("2012-01-30T05:11:00.594Z") }
//
// time 의 값을 time_t 로 읽어서 출력하기
mongo_cursor cursor;
mongo_cursor_init( &cursor, &m, "test.foo" ); // collection 을 test.foo 로 지정
while( mongo_cursor_next( &cursor ) == MONGO_OK )
{
bson_iterator iterator;
// time 필드의 값 읽어오기
if ( bson_find( &iterator, mongo_cursor_bson( &cursor ), "time" ) )
{
time_t t = bson_iterator_time_t( &iterator );
printf( "time: %s\n", ctime( &t ) );
}
}
mongo_cursor_destroy( &cursor );
}