Mongodb文档验证

时间:2017-05-04 21:11:17

标签: mongodb

我需要你对mongodb文档验证的帮助。我正在尝试创建下面的mongodb文档结构:

private void HideItems() {
for(int i = 0; i < Items.size(); i++){
    mAdapter.itemList.get(i).setThumbnail("#FFC4C4C4");
    mAdapter.itemList.get(i).setExtra("");
}
mAdapter.notifyDataSetChanged();

以下测试文档插入的命令:

db.createCollection("People2", {
  validator: {
    $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" ] }
      }
    ]
  }
})

但是得到了这个错误:

db.People2.insert(
        {
          IdentityCard: { 
             Number: "#1234",
             Type: "typeA"
          },
          lastName: "toto", 
          email: "toto@mydom.com", 
          UserVerification: "Validated"
        }
);

我认为问题来自对象“身份”验证声明,这是不正确的。

1 个答案:

答案 0 :(得分:0)

请尝试此操作,您的声明正在使用IdentityCard,而不是身份。

public bool IsContainNull(List<SanityResults> myList)
{
    foreach(var myObject in myList)
    { 
     if(myObject==null) 
      {return false;} 
     else{ 
      foreach(PropertyInfo pi in myObject.GetType().GetProperties())
            {
                if(pi.PropertyType == typeof(string))
                {
                    string stringValue = (string)pi.GetValue(myObject);
                    if(string.IsNullOrEmpty(stringValue ))
                    {
                        return true;
                    }
                }
               else if(pi.PropertyType == typeof(int))
                {
                    int intValue = (int)pi.GetValue(myObject);
                    if(intValue==null)
                    {
                        return true;
                    }
                }
            }

    }
            return false; 
相关问题