douqinlin5094 2013-10-21 09:16
浏览 164
已采纳

MongoDB更新查询,其中字段名称中包含DOT(句点)

So before I ask the question I want to say I do know that Mongo doesn't allow period i.e dot (.) in the field name.

The surprising part is that PHP was able to insert data to mongo with period in it as a field name in a multidimensional array. I use PHP version 5.4 Mongo driver 1.4.

So the array structure is somewaht like:

Array(
["field1"] => "value",
["field2"] => "123",
["field3"] => array( ["abc.def"] => array( ["test"] => "value" )
);

What I want to achieve is changing field2 value from string to integer.

Its huge data and application depends on it, i need to update the type from string to integer or from integer to string, I can control what application inserts in future but what has been entered cannot be changed, Please give me some workaround for the same.

In high hopes somebody will crack an idea upon this..!! ;)

  • 写回答

1条回答 默认 最新

  • drls2738 2013-10-21 11:16
    关注

    The best workaround that I could find was to use db.collection.update(); though i had to go thru a long procedure of excel and making similar queries for each and every row just after which i realized I could have used db.collection.find().forEach();

    So to cut down the solution use forEach to iterate and execute db.collection.update() with condition matching the data and field to update. I formatted the query as a string and then used eval();

    If you found a shorter way please do lemme know..!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler