How do I make aggregate in mongoldb witch returns the subject and the number of subjectsHow to round a number to n decimal places in JavaHow do I make the method return type generic?How to make a new List in JavaHow to make mock to void methods with MockitoMaking a mocked method return an argument that was passed to itupdate nth document in a nested array document in mongodbData type conversion in MongoDBMongoDB PHP Driver: Date search not workingConverting MongoDB timestamp to date/month/year and sortingMongoDB java get nested data

tikzcd diagram within an array

Could a space colony 1g from the sun work?

​Cuban​ ​Primes

Could there be something like aerobatic smoke trails in the vacuum of space?

Aligning group plot titles horizontally

Why do OOK transmissions have bandwidth?

Meaning of "legitimate" in Carl Jung's quote "Neurosis is always a substitute for legitimate suffering."

Why does SSL Labs now consider CBC suites weak?

Understanding Python syntax in lists vs series

Network latencies between opposite ends of the Earth

What kind of action are dodge and disengage?

My bread in my bread maker rises and then falls down just after cooking starts

What metal is most suitable for a ladder submerged in an underground water tank?

Why do galaxies collide?

Promotion comes with unexpected 24/7/365 on-call

Are there microwaves to heat baby food at Brussels airport?

Slice a list based on an index and items behind it in python

How to redirect stdout to a file, and stdout+stderr to another one?

Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?

How to rename multiple files in a directory at the same time

Testing if os.path.exists with ArcPy?

Did any "washouts" of the Mercury program eventually become astronauts?

Does it matter what way the tires go if no directional arrow?

Geometric inspiration behind Hal(irutan)'s Wolf(ram Language Logo)



How do I make aggregate in mongoldb witch returns the subject and the number of subjects


How to round a number to n decimal places in JavaHow do I make the method return type generic?How to make a new List in JavaHow to make mock to void methods with MockitoMaking a mocked method return an argument that was passed to itupdate nth document in a nested array document in mongodbData type conversion in MongoDBMongoDB PHP Driver: Date search not workingConverting MongoDB timestamp to date/month/year and sortingMongoDB java get nested data






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a database in mongodb that have three fields one the pageID, comment and the other the date.



I need to aggregate all pageID that are the same and return the count of numbers of pageID in descending order by date. I need to do this in java. Get the count of pageId that are the same.



 "_id" : ObjectId("5c93b148e3c73c03bb9b528b"), "idPagina" : "23", "date" : ISODate("2019-03-21T15:44:08.434Z"), "email" : "edw@jreww.com", "body" : "adnalf" 
"_id" : ObjectId("5c93bf4ae3c73c0598e94b44"), "idPagina" : "45", "date" : ISODate("2019-03-21T16:43:53.695Z"), "email" : "ewfn@fewr.com", "body" : "jklewnf"
"_id" : ObjectId("5c93fb6fe3c73c054600c983"), "idPagina" : "78", "date" : ISODate("2019-03-21T21:00:30.882Z"), "email" : "raphael@me.com", "body" : "jhsdbclkdbclkd"


Trying to aggregate but i need to convert to java:



db.posts.aggregate([$group : _id : "$idPagina", num_posts : $sum : 1])
"_id" : "60", "num_posts" : 1
"_id" : "56", "num_posts" : 1
"_id" : "23", "num_posts" : 31
"_id" : "30", "num_posts" : 1
"_id" : "78", "num_posts" : 1
"_id" : "45", "num_posts" : 5

MongoCollection<Document> coll = MongoFactory.getCollection(db_name, db_collection);

List<Bson> aggregation = Arrays.asList(

Aggregates.group("$idPagina", Accumulators.sum("count", 1)),

Aggregates.sort(Sorts.descending("date")),

Aggregates.project(Projections.fields(Projections.excludeId(), Projections.computed("idPagina", "$_id"), Projections.include("count"))));


Iterator<Document> sortedList = coll.aggregate(aggregation).iterator();

List<PostCount> result = new ArrayList<PostCount>();


Now how can make a pagination? Get 20 pages than get the other 20 pages after the last one?
ex:



docs = coll.find().limit(postPerPage).sort(new BasicDBObject("date", -1));


The date sorting is not working.










share|improve this question
























  • Can you post a example of your schema ?

    – Marc
    Mar 23 at 15:42











  • Check this: mkyong.com/mongodb/…

    – krishna Prasad
    Mar 23 at 16:35

















0















I have a database in mongodb that have three fields one the pageID, comment and the other the date.



I need to aggregate all pageID that are the same and return the count of numbers of pageID in descending order by date. I need to do this in java. Get the count of pageId that are the same.



 "_id" : ObjectId("5c93b148e3c73c03bb9b528b"), "idPagina" : "23", "date" : ISODate("2019-03-21T15:44:08.434Z"), "email" : "edw@jreww.com", "body" : "adnalf" 
"_id" : ObjectId("5c93bf4ae3c73c0598e94b44"), "idPagina" : "45", "date" : ISODate("2019-03-21T16:43:53.695Z"), "email" : "ewfn@fewr.com", "body" : "jklewnf"
"_id" : ObjectId("5c93fb6fe3c73c054600c983"), "idPagina" : "78", "date" : ISODate("2019-03-21T21:00:30.882Z"), "email" : "raphael@me.com", "body" : "jhsdbclkdbclkd"


Trying to aggregate but i need to convert to java:



db.posts.aggregate([$group : _id : "$idPagina", num_posts : $sum : 1])
"_id" : "60", "num_posts" : 1
"_id" : "56", "num_posts" : 1
"_id" : "23", "num_posts" : 31
"_id" : "30", "num_posts" : 1
"_id" : "78", "num_posts" : 1
"_id" : "45", "num_posts" : 5

MongoCollection<Document> coll = MongoFactory.getCollection(db_name, db_collection);

List<Bson> aggregation = Arrays.asList(

Aggregates.group("$idPagina", Accumulators.sum("count", 1)),

Aggregates.sort(Sorts.descending("date")),

Aggregates.project(Projections.fields(Projections.excludeId(), Projections.computed("idPagina", "$_id"), Projections.include("count"))));


Iterator<Document> sortedList = coll.aggregate(aggregation).iterator();

List<PostCount> result = new ArrayList<PostCount>();


Now how can make a pagination? Get 20 pages than get the other 20 pages after the last one?
ex:



docs = coll.find().limit(postPerPage).sort(new BasicDBObject("date", -1));


The date sorting is not working.










share|improve this question
























  • Can you post a example of your schema ?

    – Marc
    Mar 23 at 15:42











  • Check this: mkyong.com/mongodb/…

    – krishna Prasad
    Mar 23 at 16:35













0












0








0








I have a database in mongodb that have three fields one the pageID, comment and the other the date.



I need to aggregate all pageID that are the same and return the count of numbers of pageID in descending order by date. I need to do this in java. Get the count of pageId that are the same.



 "_id" : ObjectId("5c93b148e3c73c03bb9b528b"), "idPagina" : "23", "date" : ISODate("2019-03-21T15:44:08.434Z"), "email" : "edw@jreww.com", "body" : "adnalf" 
"_id" : ObjectId("5c93bf4ae3c73c0598e94b44"), "idPagina" : "45", "date" : ISODate("2019-03-21T16:43:53.695Z"), "email" : "ewfn@fewr.com", "body" : "jklewnf"
"_id" : ObjectId("5c93fb6fe3c73c054600c983"), "idPagina" : "78", "date" : ISODate("2019-03-21T21:00:30.882Z"), "email" : "raphael@me.com", "body" : "jhsdbclkdbclkd"


Trying to aggregate but i need to convert to java:



db.posts.aggregate([$group : _id : "$idPagina", num_posts : $sum : 1])
"_id" : "60", "num_posts" : 1
"_id" : "56", "num_posts" : 1
"_id" : "23", "num_posts" : 31
"_id" : "30", "num_posts" : 1
"_id" : "78", "num_posts" : 1
"_id" : "45", "num_posts" : 5

MongoCollection<Document> coll = MongoFactory.getCollection(db_name, db_collection);

List<Bson> aggregation = Arrays.asList(

Aggregates.group("$idPagina", Accumulators.sum("count", 1)),

Aggregates.sort(Sorts.descending("date")),

Aggregates.project(Projections.fields(Projections.excludeId(), Projections.computed("idPagina", "$_id"), Projections.include("count"))));


Iterator<Document> sortedList = coll.aggregate(aggregation).iterator();

List<PostCount> result = new ArrayList<PostCount>();


Now how can make a pagination? Get 20 pages than get the other 20 pages after the last one?
ex:



docs = coll.find().limit(postPerPage).sort(new BasicDBObject("date", -1));


The date sorting is not working.










share|improve this question
















I have a database in mongodb that have three fields one the pageID, comment and the other the date.



I need to aggregate all pageID that are the same and return the count of numbers of pageID in descending order by date. I need to do this in java. Get the count of pageId that are the same.



 "_id" : ObjectId("5c93b148e3c73c03bb9b528b"), "idPagina" : "23", "date" : ISODate("2019-03-21T15:44:08.434Z"), "email" : "edw@jreww.com", "body" : "adnalf" 
"_id" : ObjectId("5c93bf4ae3c73c0598e94b44"), "idPagina" : "45", "date" : ISODate("2019-03-21T16:43:53.695Z"), "email" : "ewfn@fewr.com", "body" : "jklewnf"
"_id" : ObjectId("5c93fb6fe3c73c054600c983"), "idPagina" : "78", "date" : ISODate("2019-03-21T21:00:30.882Z"), "email" : "raphael@me.com", "body" : "jhsdbclkdbclkd"


Trying to aggregate but i need to convert to java:



db.posts.aggregate([$group : _id : "$idPagina", num_posts : $sum : 1])
"_id" : "60", "num_posts" : 1
"_id" : "56", "num_posts" : 1
"_id" : "23", "num_posts" : 31
"_id" : "30", "num_posts" : 1
"_id" : "78", "num_posts" : 1
"_id" : "45", "num_posts" : 5

MongoCollection<Document> coll = MongoFactory.getCollection(db_name, db_collection);

List<Bson> aggregation = Arrays.asList(

Aggregates.group("$idPagina", Accumulators.sum("count", 1)),

Aggregates.sort(Sorts.descending("date")),

Aggregates.project(Projections.fields(Projections.excludeId(), Projections.computed("idPagina", "$_id"), Projections.include("count"))));


Iterator<Document> sortedList = coll.aggregate(aggregation).iterator();

List<PostCount> result = new ArrayList<PostCount>();


Now how can make a pagination? Get 20 pages than get the other 20 pages after the last one?
ex:



docs = coll.find().limit(postPerPage).sort(new BasicDBObject("date", -1));


The date sorting is not working.







java mongodb aggregation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 0:51







user5818740

















asked Mar 23 at 15:32









user5818740user5818740

85




85












  • Can you post a example of your schema ?

    – Marc
    Mar 23 at 15:42











  • Check this: mkyong.com/mongodb/…

    – krishna Prasad
    Mar 23 at 16:35

















  • Can you post a example of your schema ?

    – Marc
    Mar 23 at 15:42











  • Check this: mkyong.com/mongodb/…

    – krishna Prasad
    Mar 23 at 16:35
















Can you post a example of your schema ?

– Marc
Mar 23 at 15:42





Can you post a example of your schema ?

– Marc
Mar 23 at 15:42













Check this: mkyong.com/mongodb/…

– krishna Prasad
Mar 23 at 16:35





Check this: mkyong.com/mongodb/…

– krishna Prasad
Mar 23 at 16:35












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315381%2fhow-do-i-make-aggregate-in-mongoldb-witch-returns-the-subject-and-the-number-of%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315381%2fhow-do-i-make-aggregate-in-mongoldb-witch-returns-the-subject-and-the-number-of%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현