-
Notifications
You must be signed in to change notification settings - Fork 0
/
Array fields.py
62 lines (54 loc) · 1.28 KB
/
Array fields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Create a collection called "employees" and insert documents representing employees with fields like "name" and "skills" (an array of skills).
# Write a query to find all employees who possess a specific skill.
import pymongo
from pymongo import MongoClient
from pprint import pprint
client = MongoClient('localhost', 27017)
db = client['test']
employees = db.employees
employees_data = [{
"name": "Alice",
"skills": ["Python", "Django", "JavaScript"]
},
{
"name": "Bob",
"skills": ["JavaScript", "React", "Node.js"]
},
{
"name": "Carol",
"skills": ["Java", "Spring", "Hibernate"]
},
{
"name": "David",
"skills": ["C#", "ASP.NET", "Azure"]
},
{
"name": "Eve",
"skills": ["Ruby", "Rails", "PostgreSQL"]
},
{
"name": "Frank",
"skills": ["Python", "Flask", "JavaScript"]
},
{
"name": "Grace",
"skills": ["JavaScript", "Angular", "Node.js"]
},
{
"name": "Hannah",
"skills": ["Java", "Spring Boot", "Hibernate"]
},
{
"name": "Ivan",
"skills": ["C#", "ASP.NET Core", "Azure"]
},
{
"name": "Julia",
"skills": ["Ruby", "Sinatra", "PostgreSQL"]
}]
# employees.insert_many(employees_data)
query = {
"skills":{"$in":["JavaScript"]}
}
for employee in employees.find(query):
pprint(employee)