I'm a new Mongodb and I have a problem with $lookup with java spring.
I would like to use this shell in Spring data
db.NewFeed.aggregate([
{
$match : {username : "user001"}
},
{
$lookup:
{
from: "NewfeedContent",
localField: "content.contentId",
foreignField: "_id",
as: "NewfeedContent"
}
}
])
I found on Google but no answer yet.
Not every "new" feature makes it immediately into abstraction layers such as spring-mongo.
So instead, all you need do is define a class that uses the
AggregationOperation
interface, which will instead take a BSON Object specified directly as it's content:Then you can use in your aggregation like this:
Which shows the custom class mixed with the built in
match()
pipeline helper.All that happens underneath each helper is that they serialize to a BSON representation such as with
DBObject
anyway. So the constructor here just takes the object directly, and returns it directly from.toDBObject()
, which is the standard method on the interface that will be called when serializing the pipline contents.Here is an example:
Collection posts
Collection users
Mongodb query with lookup and match
Spring Mongoopration syntax
Joining Two Collections with Spring Data MongoDB
Employee Class
class Employee { private String _id;enter code here private String name; private String dept_id; }
Department Class
class Department { private String _id; private String dept_name; }
Employee Result Class ` public class EmpDeptResult {
}`
EmployeeSerivce `public class EmployeeService {
}`