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

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript