Click here to Skip to main content
14,383,651 members
   

Database

 
QuestionRe: Fetch data Pin
ZurdoDev25-Oct-19 5:22
professionalZurdoDev25-Oct-19 5:22 
Questionc# MongoDB Driver, find all products that contain a single brand name, and Group Distinct all category names, then get those categories. Pin
jkirkerx22-Oct-19 11:25
professionaljkirkerx22-Oct-19 11:25 
So I'm new to MongoDb; well I have about a year of experience, and I'm trying to write my first really complicated read.
What I'm trying to do, is grab a Brand by name, then all the products that match the brand name, then go through the products and get all the different distinct category names. Finally, grab the categories that match the list of category names.

So I'm just down to the final part, I have a list of distinct category names that are available by an enumerator, and I have a list of categories, I just can't figure out how to do the final part. I don't know what to call it either to search for help. I thought about a loop going through the categories, but I'm not sure how to unpack my distinct list of category names. Or perhaps the authors already thought of this and wrote something.

The categoryDistinct works.
categoriesSelected, my new list of categories
categories, a list of all the categories
var brandTask = _context.Brands.Find(b => b.Name == brandName).FirstOrDefaultAsync();

var productsFiltered = _context.Products.Find(b => b.Brand == brandName).ToList();
var categoriesDistinct = productsFiltered.GroupBy(c => c.Category).Select(x => x.FirstOrDefault());

var categoriesSelected = new List<Category>();
var categories = await context.Categories.Find( => true).ToListAsync();

// Use filters here for a more complex search of products
var productFilter = Builders<Product>.Filter.Eq("Brand", brandName);
var productsTask = _context.Products.Find(productFilter).ToListAsync();

await Task.WhenAll(brandTask, productsTask);

return new GetBrandPage { Brand = brandTask.Result, Categories = categoriesSelected, Products = productsTask.Result };
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: c# MongoDB Driver, find all products that contain a single brand name, and Group Distinct all category names, then get those categories. Pin
jkirkerx22-Oct-19 11:41
professionaljkirkerx22-Oct-19 11:41 
QuestionHow do you separate in pages database results? Pin
Joan M21-Oct-19 11:00
professionalJoan M21-Oct-19 11:00 
AnswerRe: How do you separate in pages database results? Pin
David Mujica23-Oct-19 3:48
memberDavid Mujica23-Oct-19 3:48 
QuestionI have a column and i need to find in which table this column exists throughout whole DB Pin
Anandkumar Prajapati8-Oct-19 20:29
professionalAnandkumar Prajapati8-Oct-19 20:29 
AnswerRe: I have a column and i need to find in which table this column exists throughout whole DB Pin
Victor Nijegorodov8-Oct-19 21:46
memberVictor Nijegorodov8-Oct-19 21:46 
AnswerRe: I have a column and i need to find in which table this column exists throughout whole DB Pin
Jörgen Andersson8-Oct-19 22:11
protectorJörgen Andersson8-Oct-19 22:11 
Questionvb.net connection to a firebird database Pin
Member 767827622-Sep-19 18:15
memberMember 767827622-Sep-19 18:15 
AnswerRe: vb.net connection to a firebird database Pin
Victor Nijegorodov22-Sep-19 21:12
memberVictor Nijegorodov22-Sep-19 21:12 
GeneralRe: vb.net connection to a firebird database Pin
Member 767827623-Sep-19 12:06
memberMember 767827623-Sep-19 12:06 
GeneralRe: vb.net connection to a firebird database Pin
Member 767827623-Sep-19 17:16
memberMember 767827623-Sep-19 17:16 
GeneralMessage Closed Pin
1-Oct-19 16:26
memberhayac h1-Oct-19 16:26 
QuestionMoving from access DB to Oracle to calculate average upon request Pin
Member 1447460719-Sep-19 12:12
memberMember 1447460719-Sep-19 12:12 
AnswerRe: Moving from access DB to Oracle to calculate average upon request Pin
Gerry Schmitz19-Sep-19 13:26
mveGerry Schmitz19-Sep-19 13:26 
QuestionMySQL database Pin
Alboyz17-Sep-19 17:46
memberAlboyz17-Sep-19 17:46 
AnswerRe: MySQL database Pin
#realJSOP18-Sep-19 2:08
mve#realJSOP18-Sep-19 2:08 
GeneralRe: MySQL database Pin
Alboyz18-Sep-19 17:58
memberAlboyz18-Sep-19 17:58 
AnswerRe: MySQL database Pin
Mycroft Holmes18-Sep-19 13:44
memberMycroft Holmes18-Sep-19 13:44 
GeneralRe: MySQL database Pin
Alboyz18-Sep-19 17:58
memberAlboyz18-Sep-19 17:58 
QuestionDatabase suddenly slow Pin
Super Lloyd17-Sep-19 16:39
memberSuper Lloyd17-Sep-19 16:39 
AnswerRe: Database suddenly slow Pin
CHill6018-Sep-19 1:05
protectorCHill6018-Sep-19 1:05 
GeneralRe: Database suddenly slow Pin
Super Lloyd18-Sep-19 21:47
memberSuper Lloyd18-Sep-19 21:47 
AnswerRe: Database suddenly slow Pin
Richard Deeming18-Sep-19 2:01
mveRichard Deeming18-Sep-19 2:01 
GeneralRe: Database suddenly slow Pin
Super Lloyd18-Sep-19 21:47
memberSuper Lloyd18-Sep-19 21:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.