MongoDB

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()

POM dependency

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();

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值