Michael Krog
2018-11-19 10:32:28 UTC
I am trying to create a dynamic Linq expression for searching in Mongo. But
no matter what I do it fails.
I do it like this:
Expression<Func<IndexItem, bool>> predicate = e => e.Title.Contains(text) ||
e.Description.Contains(text);
var q = collection.AsQueryable<T>().Where(predicate);
List list=q.toList()
But I always get this error:
MongoDB.Driver.MongoCommandException: Command find failed: $and/$or/$nor
must be a nonempty array.
at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.ProcessReply(ConnectionId
connectionId, ReplyMessage`1 reply)
at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.Execute(IConnection
connection, CancellationToken cancellationToken)
at
MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol`
1 protocol, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](
ICoreSession session, ReadPreference readPreference, DatabaseNamespace
databaseNamespace, BsonDocument command, IElementNameValidator
commandValidator, BsonDocument additionalOptions, Func`1 responseHandling,
Boolean slaveOk, IBsonSerializer`1 resultSerializer, MessageEncoderSettings
messageEncoderSettings, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.CommandOperationBase`1.ExecuteProtocol(IChannelHandle
channel, ICoreSessionHandle session, ReadPreference readPreference,
CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.CommandOperationBase`1.ExecuteProtocol(
IChannelSource channelSource, ICoreSessionHandle session, ReadPreference
readPreference, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.ReadCommandOperation`1.Execute(IReadBinding
binding, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.FindCommandOperation`1.Execute(
IReadBinding binding, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.FindOperation`1.Execute(IReadBinding
binding, CancellationToken cancellationToken)
at
MongoDB.Driver.OperationExecutor.ExecuteReadOperation[TResult](IReadBinding
binding, IReadOperation`1 operation, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation[TResult](IClientSessionHandle
session, IReadOperation`1 operation, ReadPreference readPreference,
CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation[TResult](IClientSessionHandle
session, IReadOperation`1 operation, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](IClientSessionHandle
session, FilterDefinition`1 filter, FindOptions`2 options,
CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](
Func`2 func, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](
FilterDefinition`1 filter, FindOptions`2 options, CancellationToken
cancellationToken)
at MongoDB.Driver.FindFluent`2.ToCursor(CancellationToken
cancellationToken)
at MongoDB.Driver.Core.Operations.AsyncCursorSourceEnumerableAdapter`
1.GetEnumerator()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1
enumerable)
at System.Collections.Generic.List`1.InsertRange(Int32 index,
IEnumerable`1 collection)
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/ec25eb34-ba2b-4a35-80a0-8425c115ca71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
no matter what I do it fails.
I do it like this:
Expression<Func<IndexItem, bool>> predicate = e => e.Title.Contains(text) ||
e.Description.Contains(text);
var q = collection.AsQueryable<T>().Where(predicate);
List list=q.toList()
But I always get this error:
MongoDB.Driver.MongoCommandException: Command find failed: $and/$or/$nor
must be a nonempty array.
at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.ProcessReply(ConnectionId
connectionId, ReplyMessage`1 reply)
at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.Execute(IConnection
connection, CancellationToken cancellationToken)
at
MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol`
1 protocol, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](
ICoreSession session, ReadPreference readPreference, DatabaseNamespace
databaseNamespace, BsonDocument command, IElementNameValidator
commandValidator, BsonDocument additionalOptions, Func`1 responseHandling,
Boolean slaveOk, IBsonSerializer`1 resultSerializer, MessageEncoderSettings
messageEncoderSettings, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.CommandOperationBase`1.ExecuteProtocol(IChannelHandle
channel, ICoreSessionHandle session, ReadPreference readPreference,
CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.CommandOperationBase`1.ExecuteProtocol(
IChannelSource channelSource, ICoreSessionHandle session, ReadPreference
readPreference, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.ReadCommandOperation`1.Execute(IReadBinding
binding, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.FindCommandOperation`1.Execute(
IReadBinding binding, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.FindOperation`1.Execute(IReadBinding
binding, CancellationToken cancellationToken)
at
MongoDB.Driver.OperationExecutor.ExecuteReadOperation[TResult](IReadBinding
binding, IReadOperation`1 operation, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation[TResult](IClientSessionHandle
session, IReadOperation`1 operation, ReadPreference readPreference,
CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation[TResult](IClientSessionHandle
session, IReadOperation`1 operation, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](IClientSessionHandle
session, FilterDefinition`1 filter, FindOptions`2 options,
CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](
Func`2 func, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](
FilterDefinition`1 filter, FindOptions`2 options, CancellationToken
cancellationToken)
at MongoDB.Driver.FindFluent`2.ToCursor(CancellationToken
cancellationToken)
at MongoDB.Driver.Core.Operations.AsyncCursorSourceEnumerableAdapter`
1.GetEnumerator()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1
enumerable)
at System.Collections.Generic.List`1.InsertRange(Int32 index,
IEnumerable`1 collection)
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/ec25eb34-ba2b-4a35-80a0-8425c115ca71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.