我想允许DiskUse:true。但是我找不到任何解释allowDiskUse启用MongoDB C#驱动程序的例子。
如何在MongoDB C#驱动程序中启用allowDiskUse?
我的示例代码
var pipeline = new[] { match, project, group, limit, sort, allow };
List<SMBMostInfluentialUser> result = db
.GetCollection<SMBTwitterStatus>("TwitterStatus")
.Aggregate(pipeline).ResultDocuments.Select(x =>
new User
{
Influence = Convert.ToDouble(x["Influence"]),
User = new SMBUser((BsonDocument)x["User"])
}).ToList();
答案 0 :(得分:4)
使用Aggregate的另一个重载来获取AggregateArgs参数,并让您更好地控制操作,包括设置AllowDiskUse:
var pipeline = new BsonDocument[0]; // replace with a real pipeline
var aggregateArgs = new AggregateArgs { AllowDiskUse = true, Pipeline = pipeline };
var aggregateResult = collection.Aggregate(aggregateArgs);
var users = aggregateResult.Select(x =>
new User
{
Influence = x["Influence"].ToDouble(),
User = new SMBUser(x["user"].AsBsonDocument)
}).ToList();
请注意,此Aggregate重载的返回类型是IEnumerable&lt; BsonDocument&gt;所以你不再需要使用ResultDocuments属性。
为了清楚起见,Select正在执行客户端。您可以对其进行排列,以便将来自聚合管道的文档直接反序列化为您的某个类的实例。
答案 1 :(得分:2)
对于更新版本的MongoDB C#驱动程序(不确定从哪个版本开始),语法为:
2018-03-26T20:13:06.206990+00:00 app[web.1]: SEVERE: Servlet [-dispatcher] in web application [] threw load() exception
2018-03-26T20:13:06.206992+00:00 app[web.1]: java.lang.ClassNotFoundException: org.springframework.web.context.DispatcherServlet
2018-03-26T20:13:06.206994+00:00 app[web.1]: at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
2018-03-26T20:13:06.206995+00:00 app[web.1]: at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
2018-03-26T20:13:06.206997+00:00 app[web.1]: at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:520)
2018-03-26T20:13:06.206999+00:00 app[web.1]: at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:501)
2018-03-26T20:13:06.207001+00:00 app[web.1]: at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
2018-03-26T20:13:06.207003+00:00 app[web.1]: at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1050)
2018-03-26T20:13:06.207004+00:00 app[web.1]: at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
2018-03-26T20:13:06.207006+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4913)
2018-03-26T20:13:06.207008+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5223)
2018-03-26T20:13:06.207009+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
2018-03-26T20:13:06.207011+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
2018-03-26T20:13:06.207028+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
2018-03-26T20:13:06.207030+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2018-03-26T20:13:06.207032+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2018-03-26T20:13:06.207033+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2018-03-26T20:13:06.207037+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748)
2018-03-26T20:13:06.207041+00:00 app[web.1]:
2018-03-26T20:13:06.239514+00:00 app[web.1]: Mar 26, 2018 8:13:06 PM org.apache.coyote.AbstractProtocol start
2018-03-26T20:13:06.239518+00:00 app[web.1]: INFO: Starting ProtocolHandler [http-nio-36917]
2018-03-26T20:13:06.808753+00:00 heroku[router]: at=info method=GET path="/" host=smok-prot-4.herokuapp.com request_id=8483e02d-3aa0-44e1-8abc-810f9f9c14ad fwd="46.22.168.229" dyno=web.1 connect=2ms service=895ms status=404 bytes=1141 protocol=https
2018-03-26T20:13:09.966331+00:00 heroku[router]: at=info method=GET path="/Application/Test" host=smok-prot-4.herokuapp.com request_id=243f54a3-9a3a-4004-8315-1ccbaa965208 fwd="46.22.168.229" dyno=web.1 connect=2ms service=14ms status=404 bytes=1141 protocol=https
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2018-03-26T20:13:06.207028+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
2018-03-26T20:13:06.207030+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2018-03-26T20:13:06.207032+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2018-03-26T20:13:06.207033+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2018-03-26T20:13:06.207037+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748)
2018-03-26T20:13:06.207041+00:00 app[web.1]:
2018-03-26T20:13:06.239518+00:00 app[web.1]: INFO: Starting ProtocolHandler [http-nio-36917]
2018-03-26T20:13:06.239514+00:00 app[web.1]: Mar 26, 2018 8:13:06 PM org.apache.coyote.AbstractProtocol start
2018-03-26T20:13:06.808753+00:00 heroku[router]: at=info method=GET path="/" host=smok-prot-4.herokuapp.com request_id=8483e02d-3aa0-44e1-8abc-810f9f9c14ad fwd="46.22.168.229" dyno=web.1 connect=2ms service=895ms status=404 bytes=1141 protocol=https
2018-03-26T20:13:09.966331+00:00 heroku[router]: at=info method=GET path="/Application/Test" host=smok-prot-4.herokuapp.com request_id=243f54a3-9a3a-4004-8315-1ccbaa965208 fwd="46.22.168.229" dyno=web.1 connect=2ms service=14ms status=404 bytes=1141 protocol=https