Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-443

Could not update an object with "$something"

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: legacy-0.0-26compat-2.6.5
    • Fix Version/s: 0.1.0
    • Component/s: None
    • Labels:
      None

      Description

      Hello,

      I am currently using the C++ driver in order to insert/update objects in a collection.

      I have the need to insert a pipeline in the object.

      Using the insert it works, but when I try to do an update, it fails telling me:

      "The dollar ($) prefixed field '$unwind' in 'pipeline.0.$unwind' is not valid for storage."

      Did you have any clue how can I make it works ?

      Here is an example of C++ code for the issue:

      std::auto_ptr<dsclient::ScopedDBConnection> mongoCnx(new dsclient::ScopedDBConnection(mongoUri));
       
       
      std::vector<mongo::BSONObj> pipeline;
      pipeline.push_back(BSON("$unwind" << "$CPN"));
      pipeline.push_back(BSON("$limit" << 10));
       
      mongo::BSONObj query = BSON(
      						"aggregate"  << "document"
      						<< "pipeline"   << pipeline
      						<< "cursor"     << BSON("batchSize" << 0));
       
      // { aggregate: "document", pipeline: [ { $unwind: "$CPN" }, { $limit: 10 } ], cursor: { batchSize: 0 } }
       
      mongo::DBClientBase* mongoDatabase = mongoCnx->getInternals()->get();
      mongoDatabase->insert("test.test_jobs", query);
       
      mongo::BSONObj updateQueryBson = BSON("_id" << mongo::OID("5487185d5bacec1fd6d560fa"));
       
      mongo::Query mongoUpdateQuery(updateQueryBson);
      // { _id: ObjectId('5487185d5bacec1fd6d560fa') }
       
      mongo::BSONObj updateQuery = BSON(
      						"aggregate"  << "store"
      						<< "pipeline"   << pipeline
      						<< "cursor"     << BSON("batchSize" << 0));
      						
      						
      mongo::BSONObj updatedBson = BSON("$set" << updateQuery );
      // { $set: { aggregate: "store", pipeline: [ { $unwind: "$CPN" }, { $limit: 10 } ], cursor: { batchSize: 0 } } }
       
      mongoDatabase->update("test.test_jobs", mongoUpdateQuery, updatedBson);
      mongoDatabase->getLastError()
       
      // Last error: The dollar ($) prefixed field '$unwind' in 'pipeline.0.$unwind' is not valid for storage.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: