how to get count of MongoDB documents in a given date range - spring

The below mentioned is the Collection used:
[
{
_id: 1,
joinedAt:ISODate("2021-07-20T12:31:33.229+05:30"),
firstName: "John",
lastName: "King",
salary: 5000,
department: {
"name": "HR"
}
},
{
_id: 2,
joinedAt:ISODate("2021-08-20T12:31:33.229+05:30"),
firstName: "Sachin",
lastName: "T",
salary: 8000,
department: {
"name": "Marketing"
}
},
{
_id: 3,
joinedAt:ISODate("2021-06-20T12:31:33.229+05:30"),
firstName: "James",
lastName: "Bond",
salary: 7500,
department: {
"name": "Marketing"
}
},
{
_id: 4,
joinedAt:ISODate("2021-05-20T12:31:33.229+05:30"),
firstName: "Rosy",
lastName: "Brown",
salary: 5000,
department: {
"name": "HR"
}
},
{
_id: 5,
joinedAt:ISODate("2021-07-26T12:31:33.229+05:30"),
firstName: "Kapil",
lastName: "D",
salary: 4500,
department: {
"name": "HR"
}
},
{
_id: 6,
joinedAt:ISODate("2021-07-20T12:31:33.229+05:30"),
firstName: "Amitabh",
lastName: "B",
salary: 7000,
department: {
"name": "Marketing"
}
}
]
I used the following query:
db.collections.aggregate([
{
$match:
{ createdAt:
{
$gte: ISODate("2021-01-01T17:06:02.713+05:30"),
$lte: ISODate("2021-12-31T17:06:02.713+05:30")
}
}
},
{$sort: {createdAt: 1}},
{ $group:{ _id:{department:'$department.name'}, totalEmployees:
{$sum:1},firstEmployee: {$first: "$firstName"} }
}])
Using this query I can get the count of employees in each department and the first name of the employee who joined first in each department. I would also like to get the count of employees joined in each department in a particular month(eg: employees joined HR department in September). What are the changes to be made in this query?

Related

I need return the user_roles in graphql query

i need return my user with your role, i'm using prisma.io and nestjs + graphql;
this is my return in graphl
{
"data": {
"login": {
"user": {
"secure_id": "1086dd35-d9ab-442a-8311-af4720ed3d9a",
"name": "Super Admin",
"email": "super#admin.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InN1cGVyQGFkbWluLmNvbSIsInN1YiI6IjEwODZkZDM1LWQ5YWItNDQyYS04MzExLWFmNDcyMGVkM2Q5YSIsImlhdCI6MTY0OTY4NDg5NSwiZXhwIjoxNjQ5Njg4NDk1fQ.bwQRzcQ_gVR2wlVGPpKdSH1yZ6e6ipmENB3NqhKeN-8"
}
}
}
and this is the console.log of the user at moment of signin:
{
id: 5,
secure_id: '1086dd35-d9ab-442a-8311-af4720ed3d9a',
name: 'Super Admin',
email: 'super#admin.com',
password: '$2b$10$ioWYGeN.luOAzB9KdUjsp.qYPkgoqLtEqqcoN05dljgXQXPkX2N6W',
created_at: 2022-04-07T19:37:22.081Z,
updated_at: 2022-04-07T19:37:22.082Z,
UserRoles: [
{
user_id: 5,
roles_id: 2,
created_at: 2022-04-07T19:37:22.096Z,
updated_at: 2022-04-07T19:37:22.096Z
}
]
}
in the log i receive the UserRoles, but not in the signin.
this is the repository: https://github.com/paulozy/tgl-nest-and-graphql

Filter data with duplicate record in kendoTreeList

In KendoJqueryTreelist, when filter data using Contains then duplicate record is not show
In KendoJqueryTreelist, when filter data using Contains then duplicate record is not show, But i require to show all record that contains(Including duplicate record) in kendo jquery treelist. filter by last name
"<script>
$("#treeList1").kendoTreeList({
columns: [
"lastName",
"position"
],
filterable: true,
dataSource: {
data: [
{ id: 1, parentId: null, lastName: "Jackson", position: "CEO" },
{ id: 2, parentId: 1, lastName: "Weber", position: " VP, Engineering" },
{ id: 1, parentId: null, lastName: "Jackson", position: "CEO" },
{ id: 4, parentId: 1, lastName: "Weber", position: " VP, Engineering" }
]
}
});
</script>"
Telerik/Kendo never likes to have duplicate id's breaks almost all of their components, I would on the server side generate a unique id for every row and add a new column if "employee-id" is used:
$("#treeList1").kendoTreeList({
columns: [
"lastName",
"position"
],
filterable: true,
dataSource: {
data: [
{ id:1, employeeId: 1, parentId: null, lastName: "Jackson", position: "CEO" },
{ id:2, employeeId: 2, parentId: 1, lastName: "Weber", position: " VP, Engineering" },
{ id:3, employeeId: 1, parentId: null, lastName: "Jackson", position: "CEO" },
{ id:4, employeeId: 4, parentId: 1, lastName: "Weber", position: " VP, Engineering" }
]
}
});
</script>"

Subobject is not parsed graphql with golang

The object itself inside the object is parsed with an empty field.
input:
{
Products(search: {limit: 1, filters: {product_id: {gte: 5}}}) {
data {
product_id
product_name
sales_history{
total_check
}
}
}
}
output:
{
"data": {
"Products": {
"data": [
{
"product_id": 35,
"product_name": "testpr",
"sales_history": {}
}
]
}
}
}
Product type:
gql.ProductType = graphql.NewObject(graphql.ObjectConfig{
Name: "Product",
Fields: graphql.Fields{
"product_id": &graphql.Field{
Type: graphql.Int,
},
"product_name": &graphql.Field{
Type: graphql.String,
},
"sales_history": &graphql.Field{
Type: gql.SalesHistoryType,
},
},
})
SalesHistory type:
gql.SalesHistoryType = graphql.NewObject(graphql.ObjectConfig{
Name: "sales_history",
Fields: graphql.Fields{
"total_check": &graphql.Field{
Type: graphql.Float,
},
},
})
In Resolve returning map in interface:
map[data:[map[product_id:35 product_name:testpr sales_history:map[total_check:671.20]]]]
I create the map"sales_history" myself, otherwise opposite the field sales_history - null
The problem was in the packaging of the final map.
It was wrong:
tmp := make(map[string]interface{}, 0)
tmp["total_check"] = v["total_check"]
v["sales_history"] = tmp
*Some fields are hidden
That`s right:
v["sales_history"] = make(map[string]interface{}, 0)
v["sales_history"].(map[string]interface{})["total_check"] = v["total_check"]

free jqGrid with Caption and without column headers

I want to display the caption, but not the column headers. When the grid is first displayed only the caption should be visible. When the grid is expanded, the column headers are visible. Please see jsFiddle
var $grid = $("#grid");
$grid.closest("div.ui-jqgrid-view")
.children("div.ui-jqgrid-hdiv")
.hide();
Here you go with a solution https://jsfiddle.net/7v70640y/5/
$("#grid").jqGrid({
colModel: [
{ name: "firstName" },
{ name: "lastName" }
],
caption: "The caption",
hiddengrid: true,
data: [
{ id: 10, firstName: "Angela", lastName: "Merkel" },
{ id: 20, firstName: "Vladimir", lastName: "Putin" },
{ id: 30, firstName: "David", lastName: "Cameron" },
{ id: 40, firstName: "Barack", lastName: "Obama" },
{ id: 50, firstName: "François", lastName: "Hollande" }
]
});
$('div[role="columnheader"]').parent().hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/css/ui.jqgrid.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/jquery.jqgrid.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css" rel="stylesheet"/>
<table id="grid"></table>
Just hide the div & it's parent div which has role as columnheader
$('div[role="columnheader"]').parent().hide();
Update with multiple jqGrid
Here you go with a solution https://jsfiddle.net/7v70640y/6/
$("#grid1").jqGrid({
colModel: [
{ name: "firstName" },
{ name: "lastName" }
],
caption: "The caption",
hiddengrid: true,
data: [
{ id: 10, firstName: "Angela", lastName: "Merkel" },
{ id: 20, firstName: "Vladimir", lastName: "Putin" },
{ id: 30, firstName: "David", lastName: "Cameron" },
{ id: 40, firstName: "Barack", lastName: "Obama" },
{ id: 50, firstName: "François", lastName: "Hollande" }
]
});
$("#grid2").jqGrid({
colModel: [
{ name: "firstName" },
{ name: "lastName" }
],
caption: "The caption",
hiddengrid: true,
data: [
{ id: 10, firstName: "Angela", lastName: "Merkel" },
{ id: 20, firstName: "Vladimir", lastName: "Putin" },
{ id: 30, firstName: "David", lastName: "Cameron" },
{ id: 40, firstName: "Barack", lastName: "Obama" },
{ id: 50, firstName: "François", lastName: "Hollande" }
]
});
$('#gview_grid1').find('div[role="columnheader"]').parent().hide();
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/css/ui.jqgrid.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/jquery.jqgrid.min.js"></script>
<table id="grid1"></table>
<br/><br/>
<table id="grid2"></table>
Hope this will help you.

How to create a nested model in kendo-mvvm

Consider the following JSON values:
[
{
OrderId: 1,
OrderName: 'order 1'
OrderItems: [
{
ProductId: 1,
ProductName: "sample name"
},
{
ProductId: 2,
ProductName: "sample name 2"
}
}
}
]
I am defining a model with this structure:
var model = kendo.data.Model.define({
id: "OrderId",
fields: {
OrderId: {
type: "number",
editable: false
},
OrderName: {
type: "string",
editable: false
},
OrderItems: {
??????????????
}
}
});
Is it possible to define a model in such a way that we can change the OrderItems during the CRUD operation?
It looks like you're mixing column definitions for your controls and the model for you orders. This simplified model will help you get started with the array of order items.
var model = kendo.data.Model.define(
{
"Order": {
"OrderId": 12345,
"OrderName": "myname",
"OrderItems": [{
"ProductId": 1,
"ProductName": "sample name"
}, {
"ProductId": 2,
"ProductName": "another product"
}]
}
}
)
You can iterate through the model.Order.OrderItems collection with $.each

Resources