現在、増分と減分を除いて、mongoddの現在の値に基づいて値を更新することはできません。
最初に各値を見つけて、それらを再度保存する前に更新する必要があります。
あなたはそれを複数の方法行うことができます:
get all profiles (only need _id and properties to update)
for each profile
set the value to its yyyy-MM-dd value
save profile
または
get all profiles (only need _id and properties to update)
create bulkOp
for each profile
set the value to its yyyy-MM-dd value
add update to bulkOp
execute bulkOp
または
aggregate to find distinct yyyy-MM-dd values
for each <yyyy-MM-dd value>
var match = {"physical.dateOfBirth": {$regex: <yyyy-MM-dd value>}};
var update = {$set: {"physical.dateOfBirth": <yyyy-MM-dd value>}};
var multi = {multi: true};
db.profiles.update(match, update, multi);
を明らかにこれは、あなたが実際のコードを試してみて、できなかっただけのプロセスです。
最後の方法は、実際にはあまりメモリに読み込まれないためです。同じ日付の値が100秒または1000秒の場合は、別の値だけをロードします。
幸運
EDIT:この線に沿って何か:
_idの$ condはちょうど1つの項目
var aggregate = db.profiles.aggregate({$group: {
_id: {$cond: ['_id', 'a', 'a']},
values: {$addToSet: { $dateToString: { format: '%Y-%m-%d', date: '$physical.dateOfBirth' } }}
}});
var values = aggregate[0].values;
for(var i = 0; i < values.length; i++) {
var date = new Date(values[i]);
var nextDay = new Date().setDate(date.getDate() + 1);
var match = {'physical.dateOfBirth': {$gte: date, $lte: nextDay}};
var update = {$set: {'physical.dateOfBirth': date}};
var multi = {multi: true};
db.profiles.update(match, update, multi);
}
で一緒にすべてを一致させることである私にクエリを教えてください –
"physical.dateOfBirth"にはどのような構造がありますか? {physical:{dateOfBirth:value}}か{'physical.dateOfBirth':value}ですか? –
これは{'physical.dateOfBirth':value} –