/*--------------------------------------------- * sql : SELECT * FROM table *--------------------------------------------- */ MongoCursor<Person> p = mongoCollection.FindAllAs<Person>(); /*--------------------------------------------- * sql : SELECT * FROM table WHERE Uid > 10 AND Uid < 20 *--------------------------------------------- */ QueryDocument query = new QueryDocument(); BsonDocument b = new BsonDocument(); b.Add("$gt", 10); b.Add("$lt", 20); query.Add("Uid", b); MongoCursor<Person> m = mongoCollection.FindAs<Person>(query); /*----------------------------------------------- * sql : SELECT COUNT(*) FROM table WHERE Uid > 10 AND Uid < 20 *----------------------------------------------- */ long c = mongoCollection.Count(query); /*----------------------------------------------- * sql : SELECT Name FROM table WHERE Uid > 10 AND Uid < 20 *----------------------------------------------- */ QueryDocument query = new QueryDocument(); BsonDocument b = new BsonDocument(); b.Add("$gt", 10); b.Add("$lt", 20); query.Add("Uid", b); FieldsDocument f = new FieldsDocument(); f.Add("Name", 1); MongoCursor<Person> m = mongoCollection.FindAs<Person>(query).SetFields(f); /*----------------------------------------------- * sql : SELECT * FROM table ORDER BY Uid DESC LIMIT 10,10 *----------------------------------------------- */ QueryDocument query = new QueryDocument(); SortByDocument s = new SortByDocument(); s.Add("Uid", -1);//-1=DESC MongoCursor<Person> m = mongoCollection.FindAllAs<Person>().SetSortOrder(s).SetSkip(10).SetLimit(10);
MongoDb在C#中查询
最新推荐文章于 2022-10-24 10:56:49 发布