Home > database >  The original query mongo polymerization into spring date mongo query
The original query mongo polymerization into spring date mongo query

Time:09-25

There is a primary statement mongo, function is aggregated I custom list and a list of the original data of intersection
The getCollection (' hb_question_standards2). Aggregate ([
{$project: {title: 1, commonToBoth: {$setIntersection: [[" pay ", "car", "mobile", "transport", "time", "train", "motor vehicle", "pay the time", "regulations", "how" and "how to pay"], "$mapDarkTitle. The word"]}}},
{$project: {title: 1, commonToBoth: 1, commonToBothSize: {size: [" $commonToBoth "]}}},
{$sort: {" commonToBothSize ": 1}},
{$limit: 30},
]);
(" pay ", "car", "mobile", "transport", "time", "train", "motor vehicle", "pay the time", "regulations", "how" and "how to pay"] is variable, and perform the above statement, get the following results (is expected results)

Now I want to have words with spring date mongo, check data after the attempt failed,
My students party, understanding is not deep enough, hope have predecessors to spend a few minutes time to give directions, I how the original statement into a corresponding spring date mongo query,

CodePudding user response:

Success has been resolved, through the interface to access the resulting
Imitation monggo original statement, beta, there has been no standard code, believe to be able to read,

List DbObjects=new ArrayList<> (a);

The Document limit=new Document ();
The Document project=new Document ();
The Document condition=new Document ();
The Document project2=new Document ();
The Document condition2=new Document ();
The Document sort=new Document ();

Condition. The put (" title ", 1);
List ListIntersects=new ArrayList<> (a);
ListIntersects. Add (words);
ListIntersects. Add (" $mapDarkTitle. The word ");
Condition. The put (" commonToBoth ", the new Document (" $setIntersection listIntersects));
Project. The put (" $project, "condition);

Condition2. Put (" title ", 1);
Condition2. Put (" commonToBoth ", 1);
Condition2. Put (" commonToBothSize ", the new Document (" size ", "$commonToBoth"));
Project2. Put (" $project, "condition2);

Sort. The put (" $sort ", the new Document (" commonToBothSize ", 1));
Limit. The put (" $limit ", 20);

DbObjects. Add (project);
DbObjects. Add (project2);
DbObjects. Add (sort);
DbObjects. Add (limit);

AggregateIterable Re=mongoTemplate. GetCollection (" hb_question_standards2 ")
Aggregate (dbObjects);

List ListDocument=new ArrayList<> (a);
For (Iterator It=re. The iterator (); It. HasNext ()) {
The Document dbo=it. Next ();
ListDocument. Add (dbo);
}

CodePudding user response:

https://blog.csdn.net/laoxiong_8080/article/details/84838858
  • Related