File notes/code/java/QuickTour.java changed (mode: 100644) (index 9695c1b..2dab14b) |
15 |
15 |
*/ |
*/ |
16 |
16 |
|
|
17 |
17 |
/* |
/* |
18 |
|
* |
|
19 |
|
* |
|
20 |
|
* |
|
|
18 |
|
* This file was edited to match our guidelines |
|
19 |
|
* and add snippets. |
|
20 |
|
* It can be executed from this folder using |
21 |
21 |
* java -cp .:../../lib/mongo-java-driver-3.9.1.jar QuickTour.java |
* java -cp .:../../lib/mongo-java-driver-3.9.1.jar QuickTour.java |
22 |
22 |
*/ |
*/ |
23 |
23 |
package tour; |
package tour; |
|
... |
... |
public class QuickTour { |
61 |
61 |
*/ |
*/ |
62 |
62 |
public static void main(final String[] args) { |
public static void main(final String[] args) { |
63 |
63 |
|
|
64 |
|
// start snippetmongoclient |
|
|
64 |
|
// start snippet mongoclient |
65 |
65 |
MongoClient mongoClient; |
MongoClient mongoClient; |
66 |
66 |
|
|
67 |
67 |
if (args.length == 0) { |
if (args.length == 0) { |
|
... |
... |
public class QuickTour { |
72 |
72 |
} |
} |
73 |
73 |
// end snippet mongoclient |
// end snippet mongoclient |
74 |
74 |
|
|
75 |
|
// start snippetdb-and-collection |
|
|
75 |
|
// start snippet db-and-collection |
76 |
76 |
// get handle to "mydb" database |
// get handle to "mydb" database |
77 |
77 |
MongoDatabase database = mongoClient.getDatabase("mydb"); |
MongoDatabase database = mongoClient.getDatabase("mydb"); |
78 |
78 |
|
|
|
... |
... |
public class QuickTour { |
83 |
83 |
// drop all the data in it |
// drop all the data in it |
84 |
84 |
collection.drop(); |
collection.drop(); |
85 |
85 |
|
|
86 |
|
// start snippetdocument-creation |
|
|
86 |
|
// start snippet document-creation |
87 |
87 |
// make a document and insert it |
// make a document and insert it |
88 |
88 |
Document doc = |
Document doc = |
89 |
89 |
new Document("name", "MongoDB") |
new Document("name", "MongoDB") |
|
... |
... |
public class QuickTour { |
98 |
98 |
Document myDoc = collection.find().first(); |
Document myDoc = collection.find().first(); |
99 |
99 |
System.out.println(myDoc.toJson()); |
System.out.println(myDoc.toJson()); |
100 |
100 |
|
|
101 |
|
// start snippetdocuments-creation |
|
|
101 |
|
// start snippet documents-creation |
102 |
102 |
// now, lets add lots of little documents to the collection so we can explore queries and |
// now, lets add lots of little documents to the collection so we can explore queries and |
103 |
103 |
// cursors |
// cursors |
104 |
104 |
List<Document> documents = new ArrayList<Document>(); |
List<Document> documents = new ArrayList<Document>(); |
|
... |
... |
public class QuickTour { |
106 |
106 |
documents.add(new Document("i", i)); |
documents.add(new Document("i", i)); |
107 |
107 |
} |
} |
108 |
108 |
collection.insertMany(documents); |
collection.insertMany(documents); |
109 |
|
// end snippetdocuments-creation |
|
|
109 |
|
// end snippet documents-creation |
110 |
110 |
System.out.println( |
System.out.println( |
111 |
111 |
"total # of documents after inserting 100 small ones (should be 101) " |
"total # of documents after inserting 100 small ones (should be 101) " |
112 |
112 |
+ collection.countDocuments()); |
+ collection.countDocuments()); |
File notes/code/xml/NSFAward.xml changed (mode: 100644) (index 5398c77..61d7efe) |
1 |
1 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
2 |
2 |
<!-- code/xml/NSFAward.xml --> |
<!-- code/xml/NSFAward.xml --> |
3 |
3 |
<rootTag> |
<rootTag> |
4 |
|
<Award> |
|
5 |
|
<AwardTitle>CAREER: Advances in Graph Learning and Inference</AwardTitle> |
|
|
4 |
|
<Award> |
|
5 |
|
<AwardTitle>CAREER: Advances in Graph Learning and Inference</AwardTitle> |
6 |
6 |
<AwardEffectiveDate>11/01/2019</AwardEffectiveDate> |
<AwardEffectiveDate>11/01/2019</AwardEffectiveDate> |
7 |
7 |
<AwardExpirationDate>01/31/2023</AwardExpirationDate> |
<AwardExpirationDate>01/31/2023</AwardExpirationDate> |
8 |
8 |
<AwardAmount>105091</AwardAmount> |
<AwardAmount>105091</AwardAmount> |
9 |
9 |
<Organization> |
<Organization> |
10 |
|
<Code>05010000</Code> |
|
11 |
|
<Directorate> |
|
12 |
|
<Abbreviation>CSE</Abbreviation> |
|
13 |
|
<LongName>Direct For Computer & Info Scie & Enginr</LongName> |
|
14 |
|
</Directorate> |
|
15 |
|
<Division> |
|
16 |
|
<Abbreviation>CCF</Abbreviation> |
|
17 |
|
<LongName>Division of Computing and Communication Foundations</LongName> |
|
18 |
|
</Division> |
|
19 |
|
</Organization> |
|
|
10 |
|
<Code>05010000</Code> |
|
11 |
|
<Directorate> |
|
12 |
|
<Abbreviation>CSE</Abbreviation> |
|
13 |
|
<LongName>Direct For Computer & Info Scie & Enginr</LongName> |
|
14 |
|
</Directorate> |
|
15 |
|
<Division> |
|
16 |
|
<Abbreviation>CCF</Abbreviation> |
|
17 |
|
<LongName>Division of Computing and Communication Foundations</LongName> |
|
18 |
|
</Division> |
|
19 |
|
</Organization> |
20 |
20 |
<ProgramOfficer> |
<ProgramOfficer> |
21 |
|
<SignBlockName>Phillip Regalia</SignBlockName> |
|
|
21 |
|
<SignBlockName>Phillip Regalia</SignBlockName> |
22 |
22 |
</ProgramOfficer> |
</ProgramOfficer> |
23 |
23 |
<AwardID>2005804</AwardID> |
<AwardID>2005804</AwardID> |
24 |
24 |
<Investigator> |
<Investigator> |
25 |
|
<FirstName>Patrick</FirstName> |
|
26 |
|
<LastName>Hopkins</LastName> |
|
27 |
|
<EmailAddress>phopkins@virginia.edu</EmailAddress> |
|
28 |
|
<StartDate>11/22/2019</StartDate> |
|
29 |
|
<EndDate /> |
|
30 |
|
<RoleCode>Co-Principal Investigator</RoleCode> |
|
|
25 |
|
<FirstName>Patrick</FirstName> |
|
26 |
|
<LastName>Hopkins</LastName> |
|
27 |
|
<EmailAddress>phopkins@virginia.edu</EmailAddress> |
|
28 |
|
<StartDate>11/22/2019</StartDate> |
|
29 |
|
<EndDate /> |
|
30 |
|
<RoleCode>Co-Principal Investigator</RoleCode> |
31 |
31 |
</Investigator> |
</Investigator> |
32 |
32 |
<Investigator> |
<Investigator> |
33 |
|
<FirstName>Jon</FirstName> |
|
34 |
|
<LastName>Ihlefeld</LastName> |
|
35 |
|
<EmailAddress>jfi4n@virginia.edu</EmailAddress> |
|
36 |
|
<StartDate>11/22/2019</StartDate> |
|
37 |
|
<EndDate /> |
|
38 |
|
<RoleCode>Principal Investigator</RoleCode> |
|
|
33 |
|
<FirstName>Jon</FirstName> |
|
34 |
|
<LastName>Ihlefeld</LastName> |
|
35 |
|
<EmailAddress>jfi4n@virginia.edu</EmailAddress> |
|
36 |
|
<StartDate>11/22/2019</StartDate> |
|
37 |
|
<EndDate /> |
|
38 |
|
<RoleCode>Principal Investigator</RoleCode> |
39 |
39 |
</Investigator> |
</Investigator> |
40 |
40 |
<Institution> |
<Institution> |
41 |
|
<Name>University of Virginia Main Campus</Name> |
|
42 |
|
<CityName>CHARLOTTESVILLE</CityName> |
|
43 |
|
<ZipCode>229044195</ZipCode> |
|
44 |
|
<PhoneNumber>4349244270</PhoneNumber> |
|
45 |
|
<StreetAddress>P.O. BOX 400195</StreetAddress> |
|
46 |
|
<CountryName>United States</CountryName> |
|
47 |
|
<StateName>Virginia</StateName> |
|
48 |
|
<StateCode>VA</StateCode> |
|
|
41 |
|
<Name>University of Virginia Main Campus</Name> |
|
42 |
|
<CityName>CHARLOTTESVILLE</CityName> |
|
43 |
|
<ZipCode>229044195</ZipCode> |
|
44 |
|
<PhoneNumber>4349244270</PhoneNumber> |
|
45 |
|
<StreetAddress>P.O. BOX 400195</StreetAddress> |
|
46 |
|
<CountryName>United States</CountryName> |
|
47 |
|
<StateName>Virginia</StateName> |
|
48 |
|
<StateCode>VA</StateCode> |
49 |
49 |
</Institution> |
</Institution> |
50 |
|
</Award> |
|
|
50 |
|
</Award> |
51 |
51 |
</rootTag> |
</rootTag> |
File notes/lectures_notes.md changed (mode: 100644) (index 3c491dc..d83615e) |
... |
... |
You will need to : |
8922 |
8922 |
- Download <https://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/3.9.1/mongo-java-driver-3.9.1.jar> from <https://oss.sonatype.org/content/repositories/releases/org/mongodb/> or from <https://github.com/mongodb/mongo-java-driver>. |
- Download <https://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/3.9.1/mongo-java-driver-3.9.1.jar> from <https://oss.sonatype.org/content/repositories/releases/org/mongodb/> or from <https://github.com/mongodb/mongo-java-driver>. |
8923 |
8923 |
- Download <https://raw.githubusercontent.com/mongodb/mongo-java-driver/master/driver-sync/src/examples/tour/QuickTour.java>. |
- Download <https://raw.githubusercontent.com/mongodb/mongo-java-driver/master/driver-sync/src/examples/tour/QuickTour.java>. |
8924 |
8924 |
|
|
8925 |
|
Place those two files, `mongo-java-driver-3.9.1.jar` and `QuickTour.java` in the same folder, and run |
|
|
8925 |
|
Place those two files, `mongo-java-driver-3.9.1.jar`{.bash} and `QuickTour.java`{.bash} in the same folder, and run |
8926 |
8926 |
|
|
8927 |
8927 |
|
|
8928 |
8928 |
```{.bash} |
```{.bash} |
8929 |
8929 |
java -cp .:mongo-java-driver-3.9.1.jar QuickTour.java |
java -cp .:mongo-java-driver-3.9.1.jar QuickTour.java |
8930 |
8930 |
``` |
``` |
8931 |
8931 |
|
|
8932 |
|
You should see a large number of lines printed, and around the top, the message `INFO: Opened connection [connectionId{localValue:2, serverValue:12}] to localhost:27017`{.bash}. |
|
|
8932 |
|
You should see a large number of lines displayed at the screen, and around the top, the message `INFO: Opened connection [connectionId{localValue:2, serverValue:12}] to localhost:27017`{.bash}. |
8933 |
8933 |
|
|
8934 |
8934 |
|
|
8935 |
8935 |
After various import statement, the program create a `MongoClient` object called `mongoClient`, and connects it to the local database server: |
After various import statement, the program create a `MongoClient` object called `mongoClient`, and connects it to the local database server: |
8936 |
8936 |
|
|
8937 |
8937 |
|
|
8938 |
|
```{.sqlmysql .numberLines include=code/java/QuickTour.java snippet=mongoclient} |
|
|
8938 |
|
```{.sqlmysql .numberLines dedent=4 include=code/java/QuickTour.java snippet=mongoclient} |
8939 |
8939 |
``` |
``` |
8940 |
8940 |
|
|
8941 |
8941 |
|
|
8942 |
8942 |
To get a database and a collection, the program uses: |
To get a database and a collection, the program uses: |
8943 |
8943 |
|
|
8944 |
|
```{.sqlmysql .numberLines include=code/java/QuickTour.java snippet=db-and-collection} |
|
|
8944 |
|
```{.sqlmysql .numberLines dedent=6 include=code/java/QuickTour.java snippet=db-and-collection} |
8945 |
8945 |
``` |
``` |
8946 |
8946 |
|
|
8947 |
|
Note that a collection is "just" an [ArrayList](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html) of documents. |
|
|
8947 |
|
Note that a collection is simply an [ArrayList](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html) of documents. |
8948 |
8948 |
|
|
8949 |
8949 |
Assume we want to create the following document: |
Assume we want to create the following document: |
8950 |
8950 |
|
|
8951 |
8951 |
```{.json} |
```{.json} |
8952 |
|
{ |
|
8953 |
|
"name" : "MongoDB", |
|
8954 |
|
"type" : "database", |
|
8955 |
|
"count" : 1, |
|
8956 |
|
"versions": [ "v3.2", "v3.0", "v2.6" ], |
|
8957 |
|
"info" : { "level" : "easy", "used" : "yes" } |
|
|
8952 |
|
{ |
|
8953 |
|
"name": "MongoDB", |
|
8954 |
|
"type": "database", |
|
8955 |
|
"count": 1, |
|
8956 |
|
"info": { |
|
8957 |
|
"x": 203, |
|
8958 |
|
"y": 102 |
8958 |
8959 |
} |
} |
|
8960 |
|
} |
8959 |
8961 |
``` |
``` |
8960 |
8962 |
|
|
8961 |
8963 |
(Remember: order does not matter!) |
(Remember: order does not matter!) |
8962 |
8964 |
|
|
8963 |
8965 |
Then we can use the `Document` class to create it, and then insert the document created: |
Then we can use the `Document` class to create it, and then insert the document created: |
8964 |
8966 |
|
|
8965 |
|
```{.sqlmysql .numberLines include=code/java/QuickTour.java snippet=document-creation} |
|
|
8967 |
|
```{.sqlmysql .numberLines dedent=6 include=code/java/QuickTour.java snippet=document-creation} |
8966 |
8968 |
``` |
``` |
8967 |
8969 |
|
|
8968 |
8970 |
Note that we can "chain" the `append`, using `doc.append("type", "database").append("count", 1);` etc. |
Note that we can "chain" the `append`, using `doc.append("type", "database").append("count", 1);` etc. |
|
... |
... |
The program goes on and is discussed in details at <https://mongodb.github.io/mo |
8991 |
8993 |
You can see for instance that to construct lists of documents and insert them, one can use: |
You can see for instance that to construct lists of documents and insert them, one can use: |
8992 |
8994 |
|
|
8993 |
8995 |
|
|
8994 |
|
```{.sqlmysql .numberLines include=code/java/QuickTour.java snippet=documents-creation} |
|
|
8996 |
|
```{.sqlmysql .numberLines dedent=4 include=code/java/QuickTour.java snippet=documents-creation} |
8995 |
8997 |
``` |
``` |
8996 |
8998 |
|
|
8997 |
8999 |
A discipline similar to what we saw on Java applications interacting with MySQL should apply: |
A discipline similar to what we saw on Java applications interacting with MySQL should apply: |
|
... |
... |
Solution +.# |
9074 |
9076 |
## Problems {-} |
## Problems {-} |
9075 |
9077 |
|
|
9076 |
9078 |
Problem (Explaining NoSQL) +.#explainNosql |
Problem (Explaining NoSQL) +.#explainNosql |
9077 |
|
~ "NoSQL" used to mean "Non `SQL`", but was retro-actively given the meaning "Not Only `SQL`." Below, write a short essay that explains: |
|
|
9079 |
|
~ |
|
9080 |
|
"NoSQL" used to mean "Non `SQL`", but was retro-actively given the meaning "Not Only `SQL`." Below, write a short essay that explains: |
|
9081 |
|
|
9078 |
9082 |
#. What motivated the "Non `SQL`" approach. |
#. What motivated the "Non `SQL`" approach. |
9079 |
9083 |
#. What is the meaning of "Not Only `SQL`." |
#. What is the meaning of "Not Only `SQL`." |
9080 |
9084 |
#. The benefits and drawbacks of the relational approach. |
#. The benefits and drawbacks of the relational approach. |