MongoDB

Posted by Bruce Tsai
03/21/2016

文件導向資料庫

MongoDB 是一種文件導向,基於分布式文件存儲的開源數據庫系統,由 C++ 撰寫而成。MongoDB 本身為 NoSQL 的一種,在使用時不需建立文件結構,直接操作資料的 CRUD 。而文件格式類似 Json,每個文件有其唯一的 key 值(_id),在使用上非常直覺。操作方式可參考 MongoDB 基礎入門教學:MongoDB Shell 篇。若想要試用而又不想自己架設伺服器,mLab 會是個好選擇。

Add document

DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
db.getCollection("restaurants").insertOne(
        new Document("address",
                new Document()
                        .append("street", "2 Avenue")
                        .append("zipcode", "10075")
                        .append("building", "1480")
                        .append("coord", asList(-73.9557413, 40.7720266)))
                .append("borough", "Manhattan")
                .append("cuisine", "Italian")
                .append("grades", asList(
                        new Document()
                                .append("date", format.parse("2014-10-01T00:00:00Z"))
                                .append("grade", "A")
                                .append("score", 11),
                        new Document()
                                .append("date", format.parse("2014-01-16T00:00:00Z"))
                                .append("grade", "B")
                                .append("score", 17)))
                .append("name", "Vella")
                .append("restaurant_id", "41704620"));

results matching ""

    No results matching ""