2014년 12월 29일 월요일

$currentDate in mongo c++ driver

Hello I wonder why this is not working:

    m_MongoDBCC.update
        (
        "test.cmds",
        Query(),
        BSON
            (
            "$currentDate" << BSON("creation_time"<<true)<<
            "cmd" << Value.m_Cmd<<
            "par0" << Value.m_Par0<<
            "par1" << Value.m_Par1
            ),
        true
        );

This command doesn't insert anything in the collection, however if I remove the $currentDate part it works fine. I have checked the documentation and as long as I understand this code should do the job.

Windows x68 64 - vs2013 - mongo 0.0-26compat-2.6.4 here.




You are attempting to create a field name that begins with a $, which is not permitted:




Thanks for answering, my question here is how do I create a new document with a field filled by the $currentDate operator.




Thanks for the clarification.

Have you examined the last error returned from the server with DBClientWithCommands::getLastError? When I run a slightly modified version of your example using legacy-1.0.0-rc3, I get the following error:

/a.out
terminate called after throwing an instance of 'mongo::OperationException'
  what():  OperationException: { index: 0, code: 9, errmsg: "Unknown modifier: cmd", op: { q: {}, u: { $currentDate: { creation_time: true }, cmd: "x", par0: "y", par1: "z" }, multi: false, upsert: true } }


Updates must either be a complete object replacement, or a complete set of $modifiers. You cannot combine the two. To achieve the effect you want here, you will need to re-write your update using $set modifier for the cmd, par0, and par1 fields.


댓글 없음:

댓글 쓰기