0
私はmongodbに少し新しく、状況があります。
私のMongoDBのコレクション内のエントリは約300Kである、私は新しいと私のコードにすべての古いエントリを移行するためにMongoDB aggregate
を使用し、私はサブストリング撮りたいということ、それを達成したい何
collection.aggregate([
{ $group: {
_id: "$_id",
"new_id" : {$substr : [{$first: "$old_id"}, 2,-1]}, //error exists here
"new_roles": {$push: "$old_role"},
}
},
{ $out: newCollection}
], {allowDiskUse:true}, function (updateError, updateResult) {
if (!updateError) {
return cb(false, true);
} else {
return cb(true, false);
}
})
のように見えますold_id
を入力してnew_id
に入力します。古いコレクションのold_idはa-112
a-34311
のようになります。これらの古いIDからa-
を削除して新しいIDに入れたいと思います。
上記のコードを試しましたが、エラーThe $substr accumulator is a unary operator
が表示されます。私はエラーを検索しようとしましたが運がありませんでした