【发布时间】:2019-07-25 06:25:38
【问题描述】:
如何使用“MongoDB.Driver”将以下 mongodb shell 脚本转换为 C#?下面的脚本在本地运行完美。脚本没有问题。但如果我将其发布为 Azure func。 “eval”操作员存在权限问题。所以我决定使用 MongoDb.Driver 将上面的脚本重写为 Native C#。我开发了下面的代码, 但是在 Azure 函数中运行时“eval”不起作用并引发错误:“Command eval failed: Command is not supported.”。我决定转换为纯 C# 代码。我该怎么做?
Date.prototype.addDays = function(h) {
this.setTime(this.getTime() + (h*60*60*1000*24));
return this;
}
var beforeDate = (new Date()).addDays(-7);
var totalDeleted = 0;
do
{
var ids = db.klm
.find({
CreatedDate: {$lt: beforeDate},
xyz: {$eq: null},
abc: {$eq: null},
Items: { $size: 0 }
})
.limit(100)
.map(function (doc) { return doc._id; });
totalDeleted += ids.length;
//db.klm.remove({"_id": { "$in": ids }});
} while (ids.length > 0);
print("Deleted " + totalDeleted + " rows before " + beforeDate);
【问题讨论】:
-
你卡在哪一部分了?
-
你可以直接从c#执行mongo脚本,你能接受吗?
-
@HariHaran,这个脚本在本地运行良好。脚本没有问题。但如果我将其发布为 Azure func。 “eval”操作员存在权限问题。所以我决定使用 MongoDb.Driver 将上面的脚本重写为 Native C#。
-
我猜@Ryan 已经为你解答了
标签: c# .net mongodb azure azure-functions