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;
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
add a comment |
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
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
add a comment |
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
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
java mongodb aggregation
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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