MongoDB is a NoSQL database with the intent of storing billions of records. It offers the aggregation framework as a tool to manipulate and query records. This tag is intended to be used with question specific to this aggregation framework, since aggregation is too general.
Questions tagged [mongodb-aggregation]
147 questions
0
votes
1 answer
customize aggregate $group outpout in node.js
I am using aggregate in node.js as follows
collection.aggregate(
{
$group : {
_id : "$id_page",
"count" : {$sum : 1}
}
},
{$sort : {"count" : -1}},
{$limit : 1}
).limit(1).toArray(function…

lemahdois
- 77
- 3
- 11
0
votes
1 answer
Mongo Cursor not returnning a cursor but an object
test_cursor = db.command({
"aggregate": "New_layout",
"pipeline": [
{ "$match": { "$and": [
{ "FIRST_DATE": { "$gte": new_date } },
{ "CHAIN_ID": { "$ne": "" } }
] } },
{ "$unwind": { "path":…

Spartan07
- 103
- 1
- 7
0
votes
1 answer
How to get individual counts of columns in a collection using mongodb query?
I am beginner in MongoDB. I need to get individual column counts from one single MongoDB query.
For example I have a collection hotelCollection with fields cityid , starRating, area, locality. Now I will pass parameter to cityid as 123 to the query…

anil
- 653
- 1
- 5
- 14
0
votes
1 answer
group and sum in aggregation with MongoDB Java Driver
I wrote this MongoDB query in Java:
db.collection.aggregate(
{ $group : {
_id : { "category" : "$category", "type" : "$type" },
number : { $sum : 1 }
} },
{ $group : {
_id : "$_id.category",
number :…

Betty
- 31
- 2
- 4
0
votes
3 answers
Aggregate pipleline Error: getMore: cursor didn't exist on server, possible restart or timeout
I am facing this issue with mongodb.
My code is something like this
for(loop) {
var cursorQuery = db.beacon_0000.aggregate([
{
$match: {
...
}
},
{
$project: {
…

Sachin Mittal
- 98
- 2
- 8
0
votes
1 answer
How to sort MongoDB results by element in array that matches a condition?
I have a collection of places which is like this :
{
"_id" : ObjectId("575014da6b028f07bef51d10"),
"name" : "MooD",
.
.
.
"categories" : [
{
"categoryList" : [Nightlife, Bar],
"weight" : 8
},
{
"categoryList" :…

Manolis Karamanis
- 758
- 1
- 10
- 27
0
votes
1 answer
How to handle division by zero in mongodb with morphia?
I found this: Handle division by zero in mongoDB useful if I were using mongoDB directly, to resolve division by zero issue, but I couldn't found a way of doing this with Morphia.
What I need to accomplish is exactly what the refered question says,…

Daniel Ardison
- 502
- 4
- 18
0
votes
2 answers
Ignore null values for $last in MongoDB aggregation
There are documents in 'account' collection. Some fields may not be declared. Look at this.
{ _id: ObjectId(1), price: 5400, product: ObjectId(2), count: 1 }
{ _id: ObjectId(1), product: ObjectId(2), count: 0, sale: 0.2 }
{…

GRiMe2D
- 654
- 1
- 10
- 22
0
votes
1 answer
How to use aggregation '$out' to migrate data between collections, but different database?
I am using aggregation framework to to migrate data from one collection to another. The following is the sample of code:
db.oldCollection.aggregate([{$out : "newCollection"}])
The indexes from oldCollection will not copied in newCollection is…

Amol M Kulkarni
- 21,143
- 34
- 120
- 164
0
votes
1 answer
Distinct in MongoDB with space in key name
I have a collection with the following structure:
{'cnpj_fundo': '08.807.621/0001-93',
'pl_posicao': 'R$ 8.654.202,31',
'posicao': [{'empresa_ligada': 'Não',
'quantidade_vendas': '',
'detalhes': "{'Tipo de Ativo:': ['Fundo de Investimento e…

fmarques
- 391
- 2
- 5
- 16
-1
votes
1 answer
Concatenating arrays nested within arrays nested within another array
Without going into how exactly I got here, can anyone help me concatenate the contents of these nested arrays using aggregation in mongo:
Concatenating
{ "missing_users" : [
[
[
…

Gary Sharpe
- 2,369
- 8
- 30
- 51
-3
votes
1 answer
Mongodb Count objects attributes
I have a collection named configurations. In configurations collection there are many companies. And each company has workstations, servers, printers, phones.
The schema for configurations is
Configuration: {
CompanyName: String
Type:…

Noman Maqsood
- 66
- 10