Does anyone expose the difference between getCollection (string name) and getCollectionFromString (string archive name) in the form of documents in Mokodi DB Can Java API?
The public DBCollection getCollectionFromString (string archive name) returns a collection that matches a given string. Parameters: Collection Name - Archive Name Returns: Collection
and
Public DBC selection getCollection (name of string) gets archived with a given name is. Parameter: Name - Archive Name Return for Return: Collection
Example with an example would be most useful (pulled from)
In response to Carl Seguin:
The collection can be identified by a namespace, "db.collection". GetCollectionFromString gets archive for that type of namespace GetCollection it only gets to the raw archive.
In those places where you require / getCollectionFromString to use some kind of mongodb management tool or possibly a CMS to do with that many databases ... dynamic-driven system It may be that the getCollection for most apps is more specific.
another :
I think what you use will really depend on your users There is hope to enter.
If they do not know anything about all the databases, then using getCollection () makes sense ... which I think is the case.
If this is a truly dynamic system and the user can say "Get me from database app 1" then getCollectionFromStirng could mean.
However, I argue that int another matter, it would be better in just two areas: database and archive. To combat this way it is more clear and simple. Your users should know how the database and archive have been separated in Doong mongodibi? For example
getCollection (strings)
:While (s.contains (".")) {Int idx = s.indexOf ("."); String b = s.sbrstring (0, idx); S = s.sstring (idx + 1); Foo = getCollection (B); } If (foo! = Null) return foo; Retrieve compilation; }package com.example.core
; Import java.net.UnknownHostException; Import java.util.Set; Import com.mongodb.db; Import com.mongodb.DBCollection; Import com.mongodb.mongo; Import com.mongodb.MongoException; / ** * Java: MongoDB * * Get access to the public category GetCollectionApp {Public Fixed Zero Main (string [] Args) {try {Mongo mongo = new Mongo ("localhost", 27017); DB DB = Mongo .get DB ("yourdb"); // Get a list of archives & lt; String & gt; Collection = db.getCollectionNames (); (String archive name: archive) {System.out.println (collectionName); } // Get a collection of DBCollection collection = db.getCollection ("yourCollection"); Println (collection.toString ()); Println ("full"); } Hold (unknownhostexception e) {e.printStackTrace (); } Hold (MongoExation E) {e.printStackTrace (); Public DBCollection getCollectionFromString (string s)) {DBCollection foo = null;
No comments:
Post a Comment