使用香草javascript,我正在使用Mongo的dpd.js来查询数据库。
在此代码段中,我尝试在集合"design"
的列roleConsiderations
中找到techniques
的所有匹配项。
roleConsiderations
中的值在数组中-["development", "design", "content"]
,所有我尝试查询"design"
的尝试都失败了。
dpd.js查询导致响应为空:
var query = {"roleConsiderations": "design"};
dpd.techniques.get(query, function (result) {
console.log(result);
});
尝试通过url查询只会返回完全匹配的内容(其中"design"
是数组中的唯一值)。
http://my.mongo.db/techniques?roleConsiderations=["design"]
那么如何在mongodb列过滤器中查询数组中的值?
答案 0 :(得分:2)
您可以使用 $ in 运算符在指定字段中指定要包含返回的对象的元素。
def login():
Username=''
Password=''
counter=0
for line in open("Credentials.txt","r").readlines(): # Read the lines
login_info = line.split() # Split on the space, and store the results in a list of two strings
while Username != login_info[0] and Password != login_info[1]: #If the username and password do not match the string elements from the txt file, starts the loop
while not (Username == login_info[0] and Password == login_info[1]):
Username = input("Please enter your username: " ) #get elements from the user
Password = input("Please enter your password: ")
print("welcome")
break
login() # call the function
我知道语法很糟糕,但是应该可以。
有关更多阅读信息,请参阅this。