Created
March 14, 2012 17:33
-
-
Save awsiv/2038095 to your computer and use it in GitHub Desktop.
Compression by timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//scons | |
//gcc -static -std=c99 -Wall compressed_data.c -I./src -L. -lbson -lmongoc -o compressed_data | |
/* compressed_promiselog.c */ | |
#include "bson.h" | |
#include "mongo.h" | |
int main() { | |
bson b, key, setOp; | |
bson_buffer bb; | |
// find right host | |
bson_buffer_init(&bb); | |
bson_append_string(&bb, "docId", "hostId1"); | |
bson_from_buffer(&key, &bb); | |
bson_buffer_init(&bb); | |
bson_buffer *setObj = bson_append_start_object(&bb, "$set"); | |
bson_append_string(setObj, "[email protected]","filehandle1"); | |
bson_append_string(setObj, "[email protected]","user1"); | |
bson_append_string(setObj, "[email protected]","filehandle2"); | |
bson_append_string(setObj, "[email protected]","user1"); | |
bson_append_finish_object(setObj); | |
bson_buffer *addToSetObj; | |
bson_buffer *timeArrayObj; | |
bson_buffer *eachObj; | |
addToSetObj = bson_append_start_object(&bb, "$addToSet"); | |
timeArrayObj = bson_append_start_object(addToSetObj, "[email protected]"); | |
eachObj = bson_append_start_array(timeArrayObj, "$each"); | |
bson_append_int(eachObj, "0", 1331201251); | |
bson_append_int(eachObj, "1", 1331218623); | |
bson_append_int(eachObj, "2", 1331285386); | |
bson_append_int(eachObj, "3", 1331302264); | |
bson_append_finish_object(eachObj); | |
bson_append_finish_object(timeArrayObj); | |
bson_append_finish_object(addToSetObj); | |
addToSetObj = bson_append_start_object(&bb, "$addToSet"); | |
timeArrayObj = bson_append_start_object(addToSetObj, "[email protected]"); | |
eachObj = bson_append_start_array(timeArrayObj, "$each"); | |
bson_append_int(eachObj, "0", 1331201251); | |
bson_append_int(eachObj, "1", 1331218623); | |
bson_append_finish_object(eachObj); | |
bson_append_finish_object(timeArrayObj); | |
bson_append_finish_object(addToSetObj); | |
bson_from_buffer(&setOp, &bb); | |
bson_print(&setOp); | |
const char * ns = "test.main"; | |
mongo_connection conn[1]; | |
mongo_connect( conn , NULL ); | |
mongo_update(conn, ns, &key, &setOp, MONGO_UPDATE_UPSERT); | |
mongo_destroy(conn); | |
bson_destroy(&setOp); | |
bson_destroy(&key); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment