mongoDB にアクセスするためのココア ラッパーとして ObjCMongoDB を使用しています。ドキュメントを検索して新しいドキュメントに置き換える必要があるシナリオで問題に直面しています。使用する ObjCMongoDB のコード/API を指摘することで、誰でも私を助けることができますか?
例えば:
{
"_id" : { "$oid" : "51de4ed737965b2d233f4862"} ,
"milestone" : "Application 7.1 release" ,
"pendingtasklist" : [ task1 , task2 , task3]
}
ここでpendingtasklist を新しいリストに置き換える必要があり、結果は次のようになります
{
"_id" : { "$oid" : "51de4ed737965b2d233f4862"} ,
"milestone" : "Application 7.1 release" ,
"someotherlist" : [ task12 , task33 , task32]
}
これを達成するために使用しているコードを添付しましたが、成功しませんでした
NSError *connectionError = nil;
MongoConnection *dbConn = [MongoConnection connectionForServer:@"127.0.0.1:27017" error:&connectionError];
MongoDBCollection *collection = [dbConn collectionWithName:@"mydb.milestones"];
MongoKeyedPredicate *predicate = [MongoKeyedPredicate predicate];
[predicate keyPath:@"milestone" matches:@"Application 7.1 release"];
MongoUpdateRequest *updateReq = [MongoUpdateRequest updateRequestWithPredicate:predicate firstMatchOnly:YES];
NSDictionary *milestoneDict = @{@"problemlist": @[@"12345",@"112244",@"55543",@"009009"],@"milestone":@"Application 7.1 release"};
[updateReq replaceDocumentWithDictionary:milestoneDict];
BOOL result = [collection updateWithRequest:updateReq error:&connectionError];
私のコレクションが次のようなドキュメントを持つ前に:
{ "_id" : { "$oid" : "51de4ed737965b2d233f4862"} , "milestone" : "Application 7.1 Release" , "problemlist" : [ 12345 , 112244 , 55543]}
{ "_id" : { "$oid" : "51de4ed737965b2d233f4864"} , "milestone" : "Application 7.1 UAT" , "problemlist" : [ 33545 , 7654 , 8767]}