Home > database >  C # API GetCollectionNames () can't get the data
C # API GetCollectionNames () can't get the data

Time:09-24

I use the shell first created a database of TTT, after I created a collection, and I insert the data, I'm sure collection to create success, the following figure

After I use the database. GetCollectionNames ()) for less than a collection of code roughly as follows:
Public void Connect (string address, string port, string username, string password)
{
String strconn=the string. Format (" mongo://{0}, {1} ", the address and port);
This. MServer=MongoServer. Create (strconn);
}
This is the connection methods, here I am sure the connection is successful
Public MongoDBTree GetMongoDBTree ()
{
List DBS=this. MServer. GetDatabaseNames () ToList ();
Return this. BuildTree (DBS);
}
Access to the database name
Private MongoDBTree BuildTree (List DBS)
{
MongoDBTree tree=new MongoDBTree ();
Tree. The Name=mServer. The Instance. The Address. The ToString ();
Tree. The NodeType=MongoDBTreeNodeType. Server;
Tree. The Children=new List (a);
The foreach (string db in DBS)
{
MongoDBTree dbTree=new MongoDBTree ();
DbTree. Name=db;
DbTree. NodeType=MongoDBTreeNodeType. Docmenu;
DbTree. Children=new List (a);
MongoDatabase database=this. MServer. GetDatabase (db);
Foreach (string item in the database. GetCollectionNames ())
{
MongoDBTree itemTree=new MongoDBTree ();
ItemTree. Name=item;
ItemTree. NodeType=MongoDBTreeNodeType. Docmenu;
DbTree. Children. The Add (itemTree);
}
Tree. The Children. The Add (dbTree);
}
Return the tree;
}
Mainly the foreach (string item in the database. The GetCollectionNames ())
API is 2.2.0 mongo is 3.2.4. Net4.5
API GetDatabase (db) method will create a if there is no database, this method also is really a wonderful work of
Don't know what's the problem, the great god for help

CodePudding user response:

Is your problem solved?

CodePudding user response:

I found a reason, not framework 4.0, GetCollectionNames (less than) data, into framework 4.5,
  • Related