0

I am making one project on MongoDB and inserted some documents and now i am updating the documents by this code..

bson_init( query );

bson_append_string(query, "First", "A");
bson_append_string(query, "Second", "B");
bson_append_string(query, "Third", "C");
bson_append_string(query, "Fourth", "D");
bson_append_string(query, "Fifth", "E");

bson_finish(query );


bson_init( b );
bson_append_start_object(b,"$set");

if(checkBox_First->isChecked() == true)
bson_append_string( b, "First", "Z");

if(checkBox_Second->isChecked() == true)
bson_append_string( b, "Second", "X");

if(checkBox_Third->isChecked() == true)
bson_append_string( b, "Third", "R");

if(checkBox_Fourth->isChecked() == true)
bson_append_string( b, "Fourth", "Y");

if(checkBox_Fifth->isChecked() == true)
bson_append_string( b, "Fifth","P");

bson_append_finish_object( b );

bson_finish(b );

mongo_update(conn,TEST_NS,query,b,MONGO_UPDATE_BASIC,0);
bson_destroy(query);
bson_destroy(b);

The code is working perfectly but after updating, the document is stored in Alphabetical order. Can anyone tell me how i can update document without sorting alphabetically. I am using "$set" Update parameter.

0

I believe the issue you were experiencing here was SERVER-2592: fields in a document are reordered (sorted alphabetically) when setting a field value.

As of the MongoDB 2.6 production release, the existing order of fields is now maintained on updates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.