python - MongoDB search for each dict in list in collection -


I have archive where list has dicts < / Code> and I want to find if a particular word has two specific key: value .

For example, I want to find find_one where my name is a word which includes a specific first and last name:

  {"name "," "", "First name": "alias", "first name": "bob", "last name": "jones", "age": "34", "gender": "m"}, "Last name": "56", "gender": "F"}, {"first name": "Bob", "last name" is a record with "Bombay's Smith" or not To see that "Smith", "age": "19", "gender": "m"},]}   

and last name, I am:

  ago = 'Bob' final = 'Smith' nameExists = db.user.find_one ({'$ and': [{'names.first name': First, '   

Post-text "itemprop =" text ">

Although it is mentioned that in reality there is no operator required, in both ways this is not the query that you want. Consider the following:

  db.user.find_one ({'names.firstName': 'alice', 'names.lastName': 'jones'})   

It actually does match the given record because "Jones" There are two elements of "first name" equal to equal "aliis" and "last name" But surely the problem here is simple that there is no real element in the array, in which there is a sub-document for those two values.

To match where the "both" criteria are given in an array element, you have to use the operator. This query condition is applied to the "element" of the array.

  db.user.find_one ({'names': {'$ elemMatch': {'firstName': 'alice', 'last name': 'Smith'}})   

And of course if you tried "Alice" and "Jones" then it does not match because in reality no element is involved in that operation.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -