0% found this document useful (0 votes)
66 views

Mongo Java Updatess

This document contains Java source code for a simple MongoDB example. It imports the MongoDB Java driver dependency, defines some sample data (names and addresses), connects to a MongoDB database locally, and provides a main method that likely inserts the sample data into a MongoDB collection and runs queries. The code is accompanied by brief documentation on MongoDB and Java integration.

Uploaded by

Kishor Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Mongo Java Updatess

This document contains Java source code for a simple MongoDB example. It imports the MongoDB Java driver dependency, defines some sample data (names and addresses), connects to a MongoDB database locally, and provides a main method that likely inserts the sample data into a MongoDB collection and runs queries. The code is accompanied by brief documentation on MongoDB and Java integration.

Uploaded by

Kishor Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

<dependency>

<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.10.1</version>
<scope>compile</scope>
</dependency>
( 1 ) Java Project
( 2 ) Java Code
?
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
package com.mkcode.mongodb!

import java.net."nkno#n$ost%&ception!
import java.te&t.'ate(ormat!
import java.te&t.)arse%&ception!
import java.te&t.*imple'ate(ormat!
import java.util.+alendar!
import java.util.'ate!
import java.util.$as,ap!
import java.util.-inked-ist!

import com.mongodb..asic'./bject!
import com.mongodb.'.!
import com.mongodb.'.+ollection!
import com.mongodb.'.+ursor!
import com.mongodb.,ongo+lient!
import com.mongodb.,ongo%&ception!

/00
0 1ava 2 ,ongo'. *imple %&ample
0
0/
public class ,ain 3


static *tring array4names56 7
381on898:im898.rit898;obin898*mit898-ora8981ennifer898-yla898<ic
tor898=dam8>!

static *tring array4address5656 73
38"*89 8(-89 8 ,iami8>9
38"*89 8(-89 8 /rlando8>9
38"*89 8+=89 8*an 'iego8>9
38"*89 8(-89 8 /rlando8>9
38"*89 8(-89 8 /rlando8>9
38"*89 8?@89 8?e# @ork8>9
38"*89 8?@89 8.uffalo8>9
38"*89 8:A89 8 $ouston8>9
38"*89 8+=89 8*an 'iego8>9
38"*89 8:A89 8 $ouston8>
>!

public static void mainB*tring56 argsC 3

try 3

// +onnect to mongodb
,ongo+lient mongo 7 ne# ,ongo+lientB8localost89 2D01DC!

( 3 ) Run
>mvn e&ecEjava
or from eclipse
Source Code i!"u#
Java$ mo%od# a%d !aed &ava$ mo%od#$ mo%od#'&ava'driver$ %os(l o% )
Post navigation
* +%s!alli% ,o%o-. o% /i%do0s 7 ,o%o-. 1 Java (2uer3i%) 4
One thought on MongoDB + Java Simpe !"ampe#
1) Jero
5"a%6s a lo!$ !"is ar!icle 0as ver3 useful for m37
8ree!i%s7
Comme%!s are closed)

$i%e us&'
Object1 Object2
Object3
(oo) *s'
Object4
Share
+echs

You might also like