blob: e1bd8d4737f27779d7cce8eb19f1c854f9b26e7f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// second.cpp
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace std;
using namespace mongo;
int main(){
DBClientConnection conn;
string errmsg;
if ( ! conn.connect( "127.0.0.1" , errmsg ) ){
cout << "couldn't connect : " << errmsg << endl;
throw -11;
}
const char * ns = "test.second";
conn.remove( ns , emptyObj );
conn.insert( ns , BUILDOBJ( "name" << "eliot" << "num" << 17 ) );
conn.insert( ns , BUILDOBJ( "name" << "sara" << "num" << 24 ) );
auto_ptr<DBClientCursor> cursor = conn.query( ns , emptyObj );
cout << "using cursor" << endl;
while ( cursor->more() ){
BSONObj obj = cursor->next();
cout << "\t" << obj.jsonString() << endl;
}
conn.ensureIndex( ns , BUILDOBJ( "name" << 1 << "num" << -1 ) );
}
|