[CXX-443] Could not update an object with "$something" Created: 09/Dec/14  Updated: 06/Apr/23  Resolved: 12/Dec/14

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: legacy-0.0-26compat-2.6.5
Fix Version/s: 0.1.0

Type: Task Priority: Major - P3
Reporter: Clement OLIVA Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate

 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.



 Comments   
Comment by Clement OLIVA [ 10/Dec/14 ]

Hello,

Thank you for your reply.

I will then check with the mongodb-user mailing list for a possible workaround.

Thank you.
Clement

Comment by Andrew Morrow (Inactive) [ 09/Dec/14 ]

Hi -

This is not actually an error with the driver, but is an error being returned from the server, which does not allow field names to start with dollar signs: http://docs.mongodb.org/manual/release-notes/2.6-compatibility/#updates-enforce-field-name-restrictions

You may want to ask on the mongodb-user mailing list to discuss workarounds for storing this type of data.

Thanks,
Andrew

Generated at Wed Feb 07 21:59:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.