com.mongodb.MongoException: Can't canonicalize query: BadValue unknown top level operator: $query

JIRA | sandip | 2 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Hi , From the java driver when I run the attached query it throws following error com.mongodb.MongoException: Can't canonicalize query: BadValue unknown top level operator: $query at com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:214) at com.mongodb.QueryResultIterator.init(QueryResultIterator.java:198) at com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:176) at com.mongodb.QueryResultIterator.<init>(QueryResultIterator.java:64) at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:86) at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66) at com.mongodb.DBCursor._check(DBCursor.java:458) at com.mongodb.DBCursor._hasNext(DBCursor.java:546) at com.mongodb.DBCursor.hasNext(DBCursor.java:571) at aap.main(aap.java:57) The code and mongodb output is here: mongos> db.test.find({$query:{}}, {"price":10}) { "_id" : 1, "price" : 10 } { "_id" : 2, "price" : 20 } { "_id" : 3, "price" : 5 } { "_id" : ObjectId("54dadd1c63108d63b47e79c3") } { "_id" : ObjectId("54e23eb9e63b0d8071b5b2af") } { "_id" : ObjectId("54e23ed3e63b0d8071b5b2b0") ================================================ java Code: MongoClient mongo = new MongoClient("<Hostname>", 27017); DB db = mongo.getDB("test"); DBCollection table = db.getCollection("test"); DBObject searchQuery = (DBObject)JSON.parse("{$query:{}}, {'price':10}"); DBCursor cursor = table.find(searchQuery); while (cursor.hasNext()) { System.out.println(cursor.next()); }

    JIRA | 2 years ago | sandip
    com.mongodb.MongoException: Can't canonicalize query: BadValue unknown top level operator: $query
  2. 0

    Hi , From the java driver when I run the attached query it throws following error com.mongodb.MongoException: Can't canonicalize query: BadValue unknown top level operator: $query at com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:214) at com.mongodb.QueryResultIterator.init(QueryResultIterator.java:198) at com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:176) at com.mongodb.QueryResultIterator.<init>(QueryResultIterator.java:64) at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:86) at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66) at com.mongodb.DBCursor._check(DBCursor.java:458) at com.mongodb.DBCursor._hasNext(DBCursor.java:546) at com.mongodb.DBCursor.hasNext(DBCursor.java:571) at aap.main(aap.java:57) The code and mongodb output is here: mongos> db.test.find({$query:{}}, {"price":10}) { "_id" : 1, "price" : 10 } { "_id" : 2, "price" : 20 } { "_id" : 3, "price" : 5 } { "_id" : ObjectId("54dadd1c63108d63b47e79c3") } { "_id" : ObjectId("54e23eb9e63b0d8071b5b2af") } { "_id" : ObjectId("54e23ed3e63b0d8071b5b2b0") ================================================ java Code: MongoClient mongo = new MongoClient("<Hostname>", 27017); DB db = mongo.getDB("test"); DBCollection table = db.getCollection("test"); DBObject searchQuery = (DBObject)JSON.parse("{$query:{}}, {'price':10}"); DBCursor cursor = table.find(searchQuery); while (cursor.hasNext()) { System.out.println(cursor.next()); }

    JIRA | 2 years ago | sandip
    com.mongodb.MongoException: Can't canonicalize query: BadValue unknown top level operator: $query
  3. 0

    QueryDSL isNotEmpty expression failing

    Stack Overflow | 2 years ago
    com.mongodb.MongoException: Can't canonicalize query: BadValue $or needs an array
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    2d sphere index in spring data mongodb

    Stack Overflow | 1 year ago | Prabjot Singh
    com.mongodb.MongoException: Unable to execute query: error processing query: ns=geolocation.items limit=0 skip=0 Tree: GEONEAR field=location maxdist=1.79769e+308 isNearSphere=0 Sort: {} Proj: {} planner returned error: unable to find index for $geoNear query
  6. 0

    Executor error: Overflow

    GitHub | 2 years ago | jmakoske
    com.mongodb.MongoException: Executor error: Overflow sort stage buffered data usage of 33556768 bytes exceeds internal limit of 33554432 byte s

  1. sriharshakiran 2 times, last 1 year ago
5 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. com.mongodb.MongoException

    Can't canonicalize query: BadValue unknown top level operator: $query

    at com.mongodb.QueryResultIterator.throwOnQueryFailure()
  2. MongoDB Java Driver
    DBCursor.hasNext
    1. com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:214)
    2. com.mongodb.QueryResultIterator.init(QueryResultIterator.java:198)
    3. com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:176)
    4. com.mongodb.QueryResultIterator.<init>(QueryResultIterator.java:64)
    5. com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:86)
    6. com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66)
    7. com.mongodb.DBCursor._check(DBCursor.java:458)
    8. com.mongodb.DBCursor._hasNext(DBCursor.java:546)
    9. com.mongodb.DBCursor.hasNext(DBCursor.java:571)
    9 frames
  3. Unknown
    aap.main
    1. aap.main(aap.java:57)
    1 frame