我最近开始使用SpringData探索MongoDB中的Aggregation Framework。我可以创建以下查询,即
db.consumer_order.aggregate([
{ $match: {_id: ObjectId("59e43f542397a00de0c688e4"), "orderState":"Confirmed"}},
{ $project: {
parts: {$filter: {
input: '$parts',
as: 'item',
cond: {$eq: ['$$item.currentState', "Estimation Confirmed"]}
}}
}}
])
Run Code Online (Sandbox Code Playgroud)
Spring在MongoDB Native Driver中使用以下代码
List<Document> aggrigationList = new ArrayList<>();
List<String> conditions = new ArrayList<>();
conditions.add("$$item.currentState");
conditions.add("Estimation Confirmed");
Document matchDoc = new Document("$match",new Document("_id",new ObjectId(orderId)));
Document projectDoc = new Document("$project",new Document("parts",new Document("$filter",new Document("input","$parts").append("as", "item").append("cond", new Document("$eq",conditions)))));
aggrigationList.add(matchDoc);
aggrigationList.add(projectDoc);
Document orderWithPendingParts = consumerOrderCollection.aggregate(aggrigationList).first();
Run Code Online (Sandbox Code Playgroud)
但我确实知道始终与本机驱动程序一起工作不是一个好习惯,因为我们已经掌握了Spring-Data。但是我无法使用Spring Data将上述MongoDB查询构造到AggrigationObject。我尝试了以下内容,但是在构造Aggregation.project()时遇到困难,即
mongoTemplate.aggregate(Aggregation.newAggregation(
Aggregation.match(Criteria.where("owner").is(user).andOperator(Criteria.where("orderState").is("confirmed"))),
***Finding Difficulty in here***
), inputType, outputType)
Run Code Online (Sandbox Code Playgroud)
指导我,如果我做错了什么。
我刚刚开始研究AngularJS并遇到了如下问题
我已经创建了一个app.js代码
var myApp = angular.module("myApp",[]);
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.when("/getAnimals",{
templateUrl: "templates/showAnimals.html",
controller:"animalController"
});
$routeProvider.when("/getBirds",{
templateUrl: "templates/showBirds.html",
controller: "birdController"
});
}]);
myApp.controller("animalController",function($scope){
$scope.message = "Hello Animal World";
});
myApp.controller("birdController",function($scope){
$scope.message = "Hello Bird World";
});
Run Code Online (Sandbox Code Playgroud)
还有一个index.html
<!DOCTYPE html>
<html ng-app = "myApp">
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script>
<script src = "app.js"></script>
</head>
<body>
<div>
<a href = "#getAnimals">Click Here to get Animals</a><br>
<a href = "#getBirds">Click Here to get Birds</a><br>
</div>
<p ng-view></p>
</body>
Run Code Online (Sandbox Code Playgroud)
但我发现这个页面没有加载,并在我检查时显示一个巨大的错误.我实际上并不了解那里发生的事情.但经过几个小时的破解,而不是给CDN我已经添加了另一个CDN即
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> …Run Code Online (Sandbox Code Playgroud) 我知道这似乎是一个愚蠢的问题,但我实际上对以下情况感到困惑,如下所示......
我明白,对于每个变量,我们需要将数据类型指定为var,或者虽然这不是一个好的做法,但我们也可以不使用var.例如,
我们可以使用
var name = "kishore";
Run Code Online (Sandbox Code Playgroud)
或者干脆
name = "kishore";
Run Code Online (Sandbox Code Playgroud)
但是,当涉及到我们作为函数中的参数传递的变量时,为什么它们不接受var?如果我没有错,我认为这些就像其他变量一样,必须存储一些可以在该函数中访问的值.如果我指定var则会给出错误.我只是想知道那里发生了什么......?
我遇到过多个例子,我对于在声明一个函数后放置分号感到困惑,它在函数内部充当函数,如下例所示
var myFunction = function() {
var value = "parentValue";
function otherFunction() {
var value = "childValue";
console.log("Value is : "+value);
}
otherFunction();
}
myFunction();
Run Code Online (Sandbox Code Playgroud)
即将分号放在otherFunction()声明的末尾.如果我保持; 或不是它的工作.哪个是最好的做法?
当我浏览与JavaScript函数相关的概念时,我想出了一些我无法弄明白的问题.我使用以下代码,即一个以return作为函数,另一个作为简单函数,如下所示
function plus(a, b) {
return(
console.log(a+b),
console.log(this),
console.log(arguments)
)
}
plus(4,5);
Run Code Online (Sandbox Code Playgroud)
和
function plus(a, b) {
console.log(a+b),
console.log(this),
console.log(arguments)
}
plus(4,5)
Run Code Online (Sandbox Code Playgroud)
但是当我同时运行时,我无法理解它,因为两者在控制台中的结果相同.所以我只想知道何时应该使用return作为函数.它的主要目的是什么?我在这里看到了答案,但那些与返回整个函数或对象相关但没有找到作为函数返回的具体答案.所以请帮助我.