2017-05-04 11 views
0

私はmongodbの初心者です。私はmongodb文書の検証にあなたの助けが必要です。私は、問題が来ると思いますMongodbドキュメントの検証

WriteResult({ 
     "nInserted" : 0, 
     "writeError" : { 
       "code" : 121, 
       "errmsg" : "Document failed validation" 
     } 
}) 

db.People2.insert(
     { 
      IdentityCard: { 
      Number: "#1234", 
      Type: "typeA" 
      }, 
      lastName: "toto", 
      email: "[email protected]", 
      UserVerification: "Validated" 
     } 
); 

しかし、このエラーを取得する:テスト文書挿入に

コマンド以下
db.createCollection("People2", { 
    validator: {`enter code here` 
    $and: [ 
     { 
     Identity: { 
      Number: { 
       $type: "string", 
       $exists: true 
      }, 
      Type: { 
       $type: "string", 
       $exists: true 
      } 
     } 
     }, 
     { 
     "lastName": { 
      $type: "string", 
      $exists: true 
     } 
     }, 
     { 
     "email": { 
      $type: "string", 
      $exists: true, 
     } 
     }, 
     { 
     UserVerification: { $in: [ "Rejected", "Validated" ] } 
     } 
    ] 
    } 
}) 

:私は、以下のMongoDB文書構造を作成しようとしていますオブジェクト "Identity"の検証宣言が正しくないことを示します。

あなたの助けはこれを試してみて、あなたの文がIdentityCardではなく、アイデンティティを使用していてください

感謝の事前

答えて

0

内をwelcome.`されるだろう。

db.createCollection("People2", { 
    validator: { 
    $and: [ 
     { 
     "IdentityCard.Number": { 
       $type: "string", 
       $exists: true 
      }, 
     "IdentityCard.Type": { 
       $type: "string", 
       $exists: true 
      } 
     }, 
     { 
     "lastName": { 
      $type: "string", 
      $exists: true 
     } 
     }, 
     { 
     "email": { 
      $type: "string", 
      $exists: true, 
     } 
     }, 
     { 
     UserVerification: { $in: [ "Rejected", "Validated" ] } 
     } 
    ] 
    } 
}) 
+0

こんにちはハーマン、よろしくお願いします。今正しく働く。 – mamkha

関連する問題