2017-09-28 2 views
0

バリデータを持つmongoコレクションをダンプ/復元しようとしています。 まず、私は私のコレクションを作成します:mongorestoreはregexバリデータを処理できますか?

use test 
db.users.drop() 
db.createCollection("users", {validator : { 
            name : { 
             $type : "string", 
             $regex : /^[A-z]*$/ 
            }, 
            } 
        }) 
// { "ok" : 1 } 
db.getCollectionInfos() 
// looks like it should... 
db.users.insertOne({"name": "[email protected]"}); 
// fails 
db.users.insertOne({"name": "Valid"}); 
// succeeds 
db.users.find() 
// { "_id" : ObjectId("59cd85d84f2803b08e9218ac"), "name" : "Valid" } 

その後、私は罰金だダンプ、実行します。

/usr/bin/mongodump --host $MYHOST \ 
        --port $MYPORT \ 
        --db test \ 
        --gzip \ 
        --archive=test.mongodump.gz 
をこれらのバリデータをインポートすることができない、表面上、それはmongorestoreのように見える正規表現を、持っています

その後、失敗し、復元:

/usr/bin/mongorestore --host $MYHOST \ 
         --port $MYPORT \ 
         --gzip \ 
         --archive=test.mongodump.gz 

エラー:

2017-09-28T23:31:30.626+0000 preparing collections to restore from 
2017-09-28T23:31:30.691+0000 reading metadata for test.users from archive 'test.mongodump.gz' 
2017-09-28T23:31:30.692+0000 Failed: test.users: error parsing metadata from archive 'test.mongodump.gz': extended json in 'options': expected $regex field to have string value 

私はmongdumpとmongorestoreにドキュメントを流しましたが、実際にはどこにもいませんでした。私は--noOptionsRestore、同じエラーを試してみました。

私はモンゴするのは比較的新しいので、私は単純な何かが欠落している可能性があり...

答えて

0

それはあなたが$の正規表現を使用している場合、あなたはまたしても$options = ''場合、$optionsが必要である、ということが判明しました。エラーメッセージのヒントの並べ替えは、非常に貧弱です。作成したステートメントを変更:

db.createCollection("users", {validator : { 
            name : { 
             $type : "string", 
             $regex : /^[A-z]*$/ 
            }, 
            } 
        }) 

db.createCollection("users", {validator : { 
            name : { 
             $type : "string", 
             $regex : /^[A-z]*$/, 
             $options: '' 
            }, 
            } 
        }) 

にすることで問題を解決し

関連する問題