I am developing an app in grails and mongodb. I am facing a very weird error. My controller class is as follows:
def report()
{
def website ="http://www.downloadaudiosongs.com/?dir&page=all"
def res = Resource.findAllByWebsite(website)
int noOfResources = res.size()
println noOfResources
}
This shows me noOfResources as 0.
This same findAllByWebsite query works in mongoDB and shows me the appropriate records.
db.resource.find({ "website": "http://www.downloadaudiosongs.com/?dir&page=all"})
But in my grails app, it doesn't fetch any records for this value of website where as for some other value, it does. I tried grails clean but nothing helped. Can anyone tell me why this might be happening?
Edit: So I think I know what is causing the issue. The ? symbol in the url is doing it because db.resource.find works for all other urls except the ones with ? and special characters. Please correct me if my understanding is flawed.
Thanks in advance.
Related
I am trying to set up an ASP.NET Core 3.1 Web API to test the elk stack using Serilog v2.9 and Serilog.Sinks.Elasticsearch v8.0.1. This is all new to me and I'm just trying to figure things out. I seem to have everything working and can log simple things all day long and see them in both ES and Kibana. Trouble is I can't seem to destructure anything except anonymous types. To illustrate:
var data = new
{
SampleData = "Hello World!"
};
_logger.LogInformation("Destructured anonymous object: {#data}", data);
Produces the expected result. A nice shiny log entry with the object "data" serialized perfectly. Whereas:
var test = new TestClass
{
Guid = Guid.NewGuid(),
Timestamp = DateTime.UtcNow,
Title = "Testing this serialization!"
};
_logger.LogInformation("Destructred discrete type. {#test}", test);
Produces nothing at all. No exception, no entry in ElasticSearch. Nothing. TestClass is a simple class with only those 3 properties, all of which should serialize just fine. I can't figure this out. Here is my LoggerConfiguration:
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticUri))
{
AutoRegisterTemplate = true,
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
CustomFormatter = new ExceptionAsObjectJsonFormatter(renderMessage: true)
})
.CreateLogger();
What am I missing? Do I have to like, produce a property map or something to destructre non-anonymous objects? Is .Net Core 3.1 too new? I'm at a loss. Every example I've seen online says this should be working.
I finally figured this out after banging my head against the problem for a few more hours. My problem is that I was using the plain old Serilog NuGet Package instead of Serilog.AspNetCore. Once I installed the latter it began working as expected.
Welp. I hope this might help anyone else in my position who is following along with the otherwise excellent guide here: https://www.humankode.com/asp-net-core/logging-with-elasticsearch-kibana-asp-net-core-and-docker
Our project uses mongodb to store its documents. We have it configured in our DataSource.groovy file with a socketTimeout of 60000. Most of our queries do not get any where near that threshold, but I assume we have it just in case something goes wrong.
Anyway, now I am working on a query that is known to be a long running query. It is pretty much guarenteed to be doing a tablespace scan, which we acknowledge and are ok with for now. The problem is the amount of data we currently have is causing it to exceed the socket timeout on random cases. Add to the issue that we are expecting the amount of data to grow considerably larger in the future.
So my question is, is it possible to increase/remove the socket timeout for a single mongodb select? I've found the following:
grailsApplication.mainContext.getBean('mongoDatastore').mongo.mongoOptions.socketTimeout = 0
That appears to work, but that also is changing the socket timeout for everything application wide I assume, which we do not want. Help!
Update: After a lot of trial and error, I found a way to open another mongo connection that reuses the configuration, but leaves off the socketTimeout and appears to work.
class MongoService {
def grailsApplication
def openMongoClientWithoutSocketTimeout() {
def datastore = grailsApplication.mainContext.getBean('mongoDatastore')
def config = grailsApplication.config.grails.mongo
def credentials = MongoCredential.createCredential(config.username, config.databaseName, config.password.toCharArray())
def options = MongoClientOptions.builder()
.autoConnectRetry(config.options.autoConnectRetry)
.connectTimeout(config.options.connectTimeout)
.build()
new MongoClient(datastore.mongo.getAllAddress(), [credentials, credentials], options)
}
def selectCollection(mongoClient, collection) {
def mongoConfig = grailsApplication.config.grails.mongo
mongoClient.getDB(mongoConfig.databaseName).getCollection(collection)
}
}
Not sure if this is the simplest solution though...
What version of mongo do you use? Possible maxTimeMS can help you?
From document page :
db.collection.find({description: /August [0-9]+, 1969/}).maxTimeMS(50)
I have created cookie for user name. Its working fine.
But my problem is:
when i clear cookie and try Cookies.getCookie("uname"); then it will return undefined insted of null.
so how to deal with undefined value ?
I am trying that if uname is not set then goes to else part;
please help me.
Yes, it is like this. Failure by design, please see here
https://code.google.com/p/google-web-toolkit/issues/detail?id=2994
The recommended workaround works:
String val = Cookies.getCookie("uname");
if (val == null || "undefined".equals(val)) {
...
} else {
...
}
But normally it seems to work even without this workaround. In my case I got the 'undefined' on JavaScript level, but in Java code it was sufficient to check for null. The real problem which let crash the code was a few lines later and didn't have anything to do with the getCookie() method. So have a look if you really identified the line with the problem.
I'm trying to call a webservice from the play framework, and I think I'm doing it wrong. I have an example call to http://www.myweather2.com/developer/forecast.ashx?uac=eDKGlpcBQN&query=52.6%2C-4.4&output=xml
A snippet from what I'm trying from the playframework is the following:
val response = WS.url("http://www.myweather2.com/developer/forecast.ashx?uac=eDKGlpcBQN&query=52.6%2C-4.4&output=xml").get.get()
val body = response.getBody
When I call this, the body consists of "useraccount does not exist". When I just put this url in a browser, I get the response I'm looking for. What am I doing wrong here?
For some reason, I was getting WS from the wrong import. When I fixed the imports to import play.api.libs.ws.WS, it worked. I'm still amazed it worked halfway with the wrong import
Don't know about "useraccount does not exist" but this seems to work:
val promise = WS.url("http://www.myweather2.com/developer/forecast.ashx?uac=eDKGlpcBQN&query=52.6%2C-4.4&output=xml").get()
val body = promise.value.get.body
Edit: Removed the space.
Also make sure your editor is not inserting a \n or \r after ?
I know this is old, but I just solved this problem while trying to do the same thing - getting the same results.
GET variables must be passed with WS.url("http://...").setQueryParameter(key, value)
Example:
val promise = WS.url("http://www.myweather2.com/developer/forecast.ashx").setQueryParameter("uac", "eDKGlpcBQN").setQueryParameter("query", "52.6%2C-4.4").setQueryParameter("output", "xml").get()
Annoying, but a relatively simple fix.
I'm trying to add a search field to my web site (ASP.NET MVC 2) and was told it'd be a good idea to use Nhibernate.Search, seeing that I was already using Nhibernate in the rest of the project.
Anyway, I followed a coulpe tutorials, namely this one, and some questions and answeres on this site, but in the end, it does not build an index, and searches come empty.
I know this question might be a bit vague, but it seems strange that nothing works even after I've done everything I was told.
Well, almost everything. At some point, in one of the tutorials, it tells me to type:
using (IFullTextSession s = Search.CreateFullTextSession(sf.OpenSession(new SearchInterceptor()))) {
QueryParser qp = new QueryParser("id", new StopAnalyzer());
IQuery NHQuery = s.CreateFullTextQuery(qp.Parse("Summary:series"), typeof(Book));
IList result = NHQuery.List();
Debug.Assert(result.Count == 2);
}
wich does not work because SearchInterceptor does not exist anywhere...
Am I missing something here?
Is there a way to better write the search queries?
In which part of my application does it build the index?
Thanks in advance.
I've tried something like:
public bool LuceneIndexAllVideos()
{
var s = NHibernate.Search.Search.CreateFullTextSession(Session);
foreach (Video video in Videos)
{
s.Index(video);
}
return true;
}
But is slow, but it seems to work nice...
See:
https://stackoverflow.com/questions/6989125/lucene-net-nhibernate-updating-lucene-index-from-existing-data