6
इस क्वेरी के साथ क्या गलत है? मैंने इसे mongodb सर्वर पर चलाने की कोशिश की और निम्नलिखित के रूप में एक त्रुटि प्राप्त हुई - "अपवाद: खराब क्वेरी: BadValue अज्ञात शीर्ष स्तर ऑपरेटर: $ gte"। क्या कोई मुझे बता सकता है कि इसमें क्या गलत है, कृपया?
db.scores.aggregate([
{
$match: {
$or: [
{ $gte: [ "$score", 30 ] },
{ $lte: [ "$score", 60 ] }
]
}
},
{
$group: {
_id: "$gamer",
games: { $sum: 1 }
}
}
])
नमूना डेटा:
{
"_id" : "545665cef9c60c133d2bce72",
"score" : 85,
"gamer" : "Latern"
}
/* 1 */
{
"_id" : "545665cef9c60c133d2bce73",
"score" : 10,
"gamer" : "BADA55"
}
/* 2 */
{
"_id" : "545665cef9c60c133d2bce74",
"score" : 62,
"gamer" : "BADA55"
}
/* 3 */
{
"_id" : "545665cef9c60c133d2bce75",
"score" : 78,
"gamer" : "l00ser"
}
/* 4 */
{
"_id" : "545665cef9c60c133d2bce76",
"score" : 4,
"gamer" : "l00ser"
}
/* 5 */
{
"_id" : "545665cef9c60c133d2bce77",
"score" : 55,
"gamer" : "FunnyCat"
}
महत्वपूर्ण बात यह है कि ['$ match' क्वेरी सिंटैक्स लेता है] (https://docs.mongodb.org/manual/reference/operator/aggregation/match/), तो आप [query' $ का उपयोग करना चाहते हैं gte' ऑपरेटर] (https://docs.mongodb.org/manual/reference/operator/query/gte/) और [एग्रीगेशन '$ gte' ऑपरेटर] नहीं (https://docs.mongodb.org/manual/ संदर्भ/ऑपरेटर/एकत्रीकरण/gte /)। (बीटीडब्ल्यू, [रेंज क्वेरी] (https://docs.mongodb.org/manual/reference/method/db.collection.find/#query-for-ranges) [अंतर्निहित '$ और'] के उपयोग के माध्यम से काम करता है (https://docs.mongodb.org/manual/reference/operator/query/and/)।) – duozmo