我的示例文档是
{
"_id" : ObjectId("51f89c1484ae3aa758ad56e9"),
"group_name" : "Operator",
"privileges" : [
"Add Group",
"Edit/Delete Group",
"Add User",
"Edit/Delete User",
"Log History",
"Add Stopwords Group",
"Edit/Delete Stopwords Group",
"Add Stopwords",
"Edit/Delete Stopwords",
"Recomended Stopwords"
],
"users" : [
{
"full_name" : "operator1",
"user_name" : "operator",
"password" : "pass$123",
"status" : "Active"
},
{
"full_name" : "Sumit Dshpande",
"user_name" : "dsumit",
"password" : "pass$123",
"status" : "Active"
}
]
}
我正在尝试匹配用户输入的用户数组中的用户名和密码。
我的Java代码是:
BasicDBObject query = new BasicDBObject();
List<BasicDBObject> parts = new ArrayList<BasicDBObject>();
parts.add(new BasicDBObject("users.user_name", uname));
parts.add(new BasicDBObject("users.password", password));
query.put("$and", parts);
DBCursor cursor = collection.find(query);
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
但它返回匹配数组中的所有用户。我希望用户在组下,以便我可以更改组权限。这是在 nosql 中进行模式设计的正确方法吗?