mongodb 基本操作

 

http://mongodb.github.io/mongo-csharp-driver/2.8/reference/driver/definitions/

https://stackoverflow.com/questions/8382307/mongodb-c-sharp-query-for-like-on-string

 

1)带时间查询

注意ISODate和本地时间差8小时

db.getCollection('DevLogCollection').find({DateTime:{'$gt':ISODate("2019-05-21T05:00:00.000Z")}})

2)模糊查询

db.getCollection('DevLogCollection').find({DeviceId:/000000000000000/})

3)正则表达式

var builder = Builders.Filter;
var filter = builder.Eq("x", 10) & builder.Lt("y", 20);

4)分页查找

var filterBuilder= Builders.Filter;
            var filter = filterBuilder.Regex("DeviceId", new BsonRegularExpression(dtuBianhao, "i"))
                & filterBuilder.Gte("DateTime",from) & filterBuilder.Lte("DateTime",to);

            var query = MongoCollection.Find(filter);
            var totalCountTask = query.CountAsync();
            var itemsTask = query.Skip(pageSize*pageIndex).Limit(pageSize).ToListAsync();

            await Task.WhenAll(totalCountTask, itemsTask);

你可能感兴趣的:(db)