Is there any easy way of firing Mongo query in Java??
db.Test.aggregate(
[
{
'$match':
{
'o': { '$gt': [] }
}
},
{
'$project': {
'uid': 1,
'o': 1
}
},
{
'$project': {
'_id': 0,
'uid': 1,
o: {
$filter: {
input: "$o",
as: "item",
cond: {
$and: [
{
$lt: [ "$$item.ad", 0 ]
},
{
$lt: [ "$$item.at", 0 ]
}
]
}
}
}
}
},
{
'$match': {
'o': { '$gt': []}
}
},
{
$project: {
uid: 1,
"mids": "$o.mid"
}
},
{
$unwind: "$mids"
},
{
$group: {
_id: {
uid: "$uid",
mid: "$mids"
},
count: { $sum: 1 }
}
},
{
$project: {
_id: 0,
uid: "$_id.uid",
mid: "$_id.mid",
count: 1
}
}
]
);
Is http://jongo.org serve the purpose for complex queries?
As an alternative, you can use the Java driver's Document.parse()
method. You can supply a JSON string to the method (following MongoDB's extended JSON formatting ), and it will return a parsed BSON document for you.
Please see http://mongodb.github.io/mongo-java-driver/3.5/javadoc/org/bson/Document.html#parse-java.lang.String- for the method's documentation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.