0
我最近开始使用MongoDB作为SSIS中的源代码(使用C#驱动程序)。我对MongoDB和C#非常新。 当我没有嵌套的文件,如下面的语句为我工作:
var query = Query.And(Query.Or(Query.GT("CreatedOn",maxUpdatedOnBSON), Query.GT("UpdatedOn", maxUpdatedOnBSON)),
Query.Or(Query.LT("CreatedOn", cutoffDate), Query.LT("UpdatedOn", cutoffDate)),Query.In("TestType", testTypes));
MongoCursor<BsonDocument> toReturn = collection.Find(query);
现在,我得到了嵌套的文件。我能够创建Java脚本,并将其与MongoDB的本身
db.Test.aggregate([
{ $unwind : { path: "$Items",includeArrayIndex: "arrayIndex"} } ,
{ $match: { $and: [
{$or: [ { CreatedOn: { $gt: ISODate("2015-11-22T00:00:00Z")} }, {UpdatedOn: { $gt: ISODate("2015-11-22T00:00:00Z") } } ] },
{$or: [ { CreatedOn: { $lt: ISODate("2016-05-09T00:00:00Z")} }, {UpdatedOn: { $lt: ISODate("2016-05-09T00:00:00Z") } } ] }
] }
}])
工作在C#中,我明白了,我必须使用的总,而不是找到,但我不能把这种代码转换为C#。我仍然有选择标准和放松。
你能帮忙吗?
我希望如此。将尝试这种方法,谢谢。问题是关于MongoCursor语法。 MongoCursor toReturn = collection。?; –
ICHV
好,如果你想要一个聚合的游标,你需要聚合或将聚合选项传递给聚合构件。或上面编辑的答案。你不能让MongoCursor离开它。你可以像这样获得IAsyncCursor var aggCursor = grades.Aggregate() .Unwind(x => x [“Items”]) .Match(filter).ToCursor(); – KaSh
看看这个链接的详细信息asynccursor http://stackoverflow.com/questions/29682371/how-is-an-iasynccursor-used-for-iteration-with-the-mongodb-c-sharp-driver? RQ = 1 – KaSh