MongoDB Project Integration Mongo-driver 3.4.2

Source: Internet
Author: User
Tags mongoclient sonatype



First time writing technology! Plain English talk about it. Just take it with you.






I am, net of technical staff, will point Java so a lot of unprofessional, forgive Ha






I just started using MONGO for two days before I got a half-bucket of water.






Casually put MONGO in Win's build also write down. Actually, this is nothing to write about. Very simple






I'm using the latest version of MONGO.



Installed directory is C-drive






Then the database is placed underneath the other disks.



Create a new directory based on the following command. MongoDB.log, this is not a new one.



Create a new MONGO service. This will allow you to use the boot.





[Plain]View PlainCopy
    1. Mongod--dbpath O:\mongodb\data\db--logpath O:\mongodb\data\log\MongoDB.log--install--servicename Mongodbmet



In this case, you will be presented with our new server. A little do not know how, my service name is not actually written by myself, has been MongoDB









Now the library is basically built up. Especially want to build a cluster. But I don't know how to build it. Still in the study.



The use of management tools is a headache, I found two online, as if not support the latest MONGO library, do not know whether the cause of the configuration or what



It's best not to use the Charge management tool "NoSQL Manager for MongoDB" This is very powerful, easy to use, compatible with the latest library















Start Java link Now there's a hole in this place, and maybe it's a hole for me. is to use Mongodb-driver-3.4.2.jar This package must be used in conjunction with the other two packages. Mongodb-driver-core-3.4.2.jar and Bson-3.4.2.jar, respectively, were just beginning to know, and the first one was quoted. No errors were written. operation on the error. Link is not on MongoDB, at that time saw a lot of dishes to understand, there is this three package must be the same version, or it is an error. I'm using the latest 3.4.2. It's all up to date. Now use normal






Post Code now





[Java]View PlainCopy


Mongoclient mongoclient = null;

Mongodatabase database = null;

mongocollection<document> collection = null;

Public Metstrfy () {

String mongohost = Setsystemproperty.readvalue ("Mongohost"); Address

String MONGODK = Setsystemproperty.readvalue ("MONGODK"); Port

String mongofydb = Setsystemproperty.readvalue ("Mongofydb"); Database name

String mongofydata = Setsystemproperty.readvalue ("Mongofydata"); Table name

Mongoclient = New Mongoclient (Mongohost, Integer.parseint (MONGODK));

Database = Mongoclient.getdatabase (MONGOFYDB);

Collection = Database.getcollection (Mongofydata);

}



Send ID query information out. The return is in JSON format OH. Change it yourself,


[Java]View PlainCopy
    1. Public string Getmodel (String Pmid) {
    2. Metfymodel model = new Metfymodel ();
    3. Document MyDoc = Collection.find (new Basicdbobject ("id", ID)). First ();
    4. Mongoclient.close ();
    5. return Mydoc.tojson ();
    6. //return model;
    7. }


All right. The rest of the road is still a lot. I have to study it slowly.






Use of the package sent to everyone, you can try the hair ha






Https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb-driver-core/3.4.2/mongodb-driver-core-3.4.2.jar






Https://oss.sonatype.org/content/repositories/releases/org/mongodb/bson/3.4.2/






Https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb-driver/3.4.2/






MongoDB Project Integration Mongo-driver 3.4.2


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.