MongoDB is an open-source, document database designed for ease of development and scaling.
mongod --dbpath=E:\MongoDB\data
mongoimport.exe --db test --collection restaurants --drop --file primer-dataset.json
use test
db.restaurants.insert(
{
"address" : {
"street" : "2 Avenue",
"zipcode" : "10075",
"building" : "1480",
"coord" : [ -73.9557413, 40.7720266 ]
},
"borough" : "Manhattan",
"cuisine" : "Italian",
"grades" : [
{
"date" : ISODate("2014-10-01T00:00:00Z"),
"grade" : "A",
"score" : 11
},
{
"date" : ISODate("2014-01-16T00:00:00Z"),
"grade" : "B",
"score" : 17
}
],
"name" : "Vella",
"restaurant_id" : "41704620"
}
)
db.restaurants.find()
db.restaurants.find({"borough":"Queens"})
db.restaurants.find({"address.zipcode":"10462"})
db.restaurants.drop()
db.dropDatabase()
public class MyMongodbTest {
public static void main(String[] args) {
MongoClient mongo = new MongoClient();
MongoDatabase db = mongo.getDatabase("testDB");
MongoCollection table = db.getCollection("message");
Document document = new Document();
document.put("name", "aaaa");
document.put("code", 123456);
table.insertOne(document);
System.out.println(table.count());
BasicDBObject oneYear = new BasicDBObject("code", -1);
FindIterable<Document> documents = table.find().sort(oneYear);
documents.forEach(new Block<Document>() {
public void apply(Document document) {
System.out.println(document);
}
});
table.drop();
}
}