各語言連接mongodb

  1. java

    MongoClient mongoClient;
    MongoCredential credential = MongoCredential.createCredential(“user”, “database”, “password”);
    mongoClient = new MongoClient(new ServerAddress(ip, port), Arrays.asList(credential));

  2. python

    from pymongo import MongoClient
    client = MongoClient(“ip”,port)
    client.database.authenticate(“user”,”password”)
    db = client.database
    collection = db.collection

  3. nodejs

    var mongoose = require(“mongoose”);
    mongoose.connect(“mongodb://username:password@localhost:27017/test”);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章