Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown top level operator: $where #174

Open
mantasmatuzas opened this issue Dec 23, 2020 · 6 comments
Open

Unknown top level operator: $where #174

mantasmatuzas opened this issue Dec 23, 2020 · 6 comments
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed.

Comments

@mantasmatuzas
Copy link

mantasmatuzas commented Dec 23, 2020

Firstly, I want to thank for such a wonderful project. Unfortunately, our team gets this error on 1.36 version. Is it possible to fix this?

Stacktrace:

14:25:40.107 [mongo-server-worker2] ERROR d.b.m.wire.MongoWireProtocolHandler - failed to handle query MongoQuery(header: MessageHeader(request: 1794, responseTo: 0, length: 156), collection: test.XXX, query: {"$orderby" : {"name" : 1}, "$query" : {"$or" : [ { "$where" : "\"\\Q\\E\" == null" }, { "name" : "{\"$regex\" : \"\\\\Q\\\\E\", \"$options\" : \"i\"}" } ]}}, returnFieldSelector: null)
de.bwaldvogel.mongo.exception.BadValueException: [Error 2] unknown top level operator: $where
	at de.bwaldvogel.mongo.backend.DefaultQueryMatcher.checkMatch(DefaultQueryMatcher.java:121)
	at de.bwaldvogel.mongo.backend.DefaultQueryMatcher.checkMatch(DefaultQueryMatcher.java:97)
	at de.bwaldvogel.mongo.backend.DefaultQueryMatcher.matches(DefaultQueryMatcher.java:38)
	at de.bwaldvogel.mongo.backend.DefaultQueryMatcher.checkMatch(DefaultQueryMatcher.java:278)
	at de.bwaldvogel.mongo.backend.DefaultQueryMatcher.checkMatch(DefaultQueryMatcher.java:119)
	at de.bwaldvogel.mongo.backend.DefaultQueryMatcher.checkMatch(DefaultQueryMatcher.java:97)
	at de.bwaldvogel.mongo.backend.DefaultQueryMatcher.matches(DefaultQueryMatcher.java:38)
	at de.bwaldvogel.mongo.backend.AbstractMongoCollection.documentMatchesQuery(AbstractMongoCollection.java:56)
	at de.bwaldvogel.mongo.backend.AbstractMongoCollection.lambda$matchDocumentsFromStream$0(AbstractMongoCollection.java:85)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
	at de.bwaldvogel.mongo.backend.AbstractMongoCollection.matchDocumentsFromStream(AbstractMongoCollection.java:104)
	at de.bwaldvogel.mongo.backend.AbstractMongoCollection.matchDocumentsFromStream(AbstractMongoCollection.java:77)
	at de.bwaldvogel.mongo.backend.memory.MemoryCollection.matchDocuments(MemoryCollection.java:60)
	at de.bwaldvogel.mongo.backend.AbstractMongoCollection.queryDocuments(AbstractMongoCollection.java:68)
	at de.bwaldvogel.mongo.backend.AbstractMongoCollection.handleQuery(AbstractMongoCollection.java:450)
	at de.bwaldvogel.mongo.backend.AbstractSynchronizedMongoCollection.handleQuery(AbstractSynchronizedMongoCollection.java:29)
	at de.bwaldvogel.mongo.MongoCollection.lambda$handleQueryAsync$0(MongoCollection.java:72)
	at de.bwaldvogel.mongo.util.FutureUtils.wrap(FutureUtils.java:9)
	at de.bwaldvogel.mongo.MongoCollection.handleQueryAsync(MongoCollection.java:72)
	at de.bwaldvogel.mongo.backend.AbstractMongoDatabase.handleQueryAsync(AbstractMongoDatabase.java:687)
	at de.bwaldvogel.mongo.backend.AbstractMongoBackend.handleQueryAsync(AbstractMongoBackend.java:392)
	at de.bwaldvogel.mongo.wire.MongoDatabaseHandler.handleQueryAsync(MongoDatabaseHandler.java:125)
	at de.bwaldvogel.mongo.wire.MongoDatabaseHandler.channelRead0(MongoDatabaseHandler.java:73)
	at de.bwaldvogel.mongo.wire.MongoDatabaseHandler.channelRead0(MongoDatabaseHandler.java:34)
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at java.base/java.lang.Thread.run(Thread.java:834)
@bwaldvogel
Copy link
Owner

Hm, I’m not sure if this is easily possible to add. If I understood it correctly, the $where operator would basically require to execute a Javascript expression?

@mantasmatuzas
Copy link
Author

mantasmatuzas commented Dec 28, 2020

In my case, the usage of this operator looks like this:

@Query("{$or : [{$where : '\"?0\" == null'}, {'name' : {$regex: ?0, $options: 'i'}}]}")
List<Group> findGroupsLike(String name, Sort sort);

As I see in Mongo documentation, Javascript should be passed to $where clause so probably you are right.
Strangely, but with Fongo it worked (we used it previously). So maybe there would be opportunity to reuse their solution?

@bwaldvogel
Copy link
Owner

Could you point me to the solution that Fongo uses?

@mantasmatuzas
Copy link
Author

mantasmatuzas commented Dec 29, 2020

Could you point me to the solution that Fongo uses?

Check here

As I see they use Mozilla Rhino library, an Java implementation of JavaScript

@zpapez
Copy link

zpapez commented Nov 22, 2021

Is this somehow considered for implementation?

@bwaldvogel
Copy link
Owner

Unfortunately I won’t be able to implement this any time soon by myself but I’m happy to receive a pull request.

@bwaldvogel bwaldvogel added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed.
Projects
None yet
Development

No branches or pull requests

3 participants