I want to take a record randomly from MongoDB using Linq in C#. Here is what I'm doing.
public string RandomWord()
{
using (Mongo mongo = new Mongo(_mongoConfig.BuildConfiguration()))
{
try
{
mongo.Connect();
var db = mongo.GetDatabase(_dbName);
IMongoCollection<dic_words> collection = db.GetCollection<dic_words>();
return
(from w in collection.Linq()
where w.word.Length > 2
orderby Guid.NewGuid()
select w).Take(1).FirstOrDefault().word;
}
catch (Exception)
{
throw;
}
}
}
And here is the error I got
The query is too complex to be processed by MongoDB. Try building a map-reduce query by hand or simplifying the query and using Linq-to-Objects.
Thanks in advance.