1

I'm new in mongo. I'm wrting code in C# that get information from MongoDB. I need to get records that fit some terms, but I only know how to write queries that fit one term. For example, this code:

var connectionString = ConfigurationManager.AppSettings["MongoAddress"];
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("Gnip");
var collection = database.GetCollection<DOC>("GnipUL");                
var query2 = Query<DOC>.EQ(e1 => e1.Type, iType);
var search = collection.Find(query2);`

Gets records where the field 'Type' is equal to iType. How do I change this code to find records there the field 'Type' is equal to iType, and the field 'Taken' is equel to 1.

Tom Zych
  • 13,329
  • 9
  • 36
  • 53

1 Answers1

0

I think you can do something like this:

var query3  = Query.And(
                Query<DOC>.EQ(e1 => e1.Type, iType),
                Query<DOC>.EQ(e1 => e1.Taken, 1)
              );
S.Spieker
  • 7,005
  • 8
  • 44
  • 50
  • Another question that based on the previous question: let's say i want to get top 50 records of the query. I saw this question: http://stackoverflow.com/questions/4421207/mongodb-how-to-get-the-last-n-records , and i don't know how to implement it in my code. I can't add to the line collection.Find(query2), '.sort(.. – user2268845 Jul 06 '14 at 13:43