Вопрос

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..!! ;)

Это было полезно?

Решение

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..!!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top