C# MONGODB查找产品编号
我有一个MONGODB,有一些测试结果(>25.000),DB包含大约50个产品编号 我有没有办法得到一份产品编号的清单?(~50而非>25000) 我使用C#和指南针 我想这很简单:-) 顺致敬意,C# MONGODB查找产品编号,c#,mongodb,compass,C#,Mongodb,Compass,我有一个MONGODB,有一些测试结果(>25.000),DB包含大约50个产品编号 我有没有办法得到一份产品编号的清单?(~50而非>25000) 我使用C#和指南针 我想这很简单:-) 顺致敬意, SPA..首先,如果您想与MongoDB进行交互,您必须在代码顶部添加以下代码行,每行代码上方都有: using MongoDB.Bson; using MongoDB.Driver; using MongoDB.Driver.Builders; using MongoDB.Drive
SPA..首先,如果您想与MongoDB进行交互,您必须在代码顶部添加以下代码行,每行代码上方都有:
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Driver.GridFS;
using MongoDB.Driver.Linq;
现在我们将创建到DB的连接:
MongoClient client = new MongoClient(your_connection_string);
MongoServer server = client.GetServer();
MongoDatabase database = server.GetDatabase(your_db_name);
现在是创建数据集合的时候了:
MongoCollection resultsCollection = null;
try
{
resultsCollection = database.GetCollection<results>(your_results_name);
Console.WriteLine(resultsCollection.Count().ToString());
}
catch (Exception ex)
{
Console.WriteLine("Failed to Get collection from Database");
Console.WriteLine("Error :" + ex.Message);
}
备注:
如果只想从查询中获得x个结果,则必须使用
.Limit(行数)
似乎要按产品编号进行分组。当你搜索c#mongodb groupby时,你会发现很多例子。如果你有具体的问题,把你有的和不起作用的张贴出来——我们是来帮助你的。
List< Results > query = resultsCollection.AsQueryable<Entity>().Where<Entity>(your_where_statement).Limit(50).ToList();
public class Results
{
public string Name { get; set; }
public ObjectId ID { get; set; }
}