MongoDB shell : print results - mongodb

If I execute ONLY the 1st part of the following short script in Robo3T, I get the results printed to the screen.
If I execute it with 2nd part, I only get the standard answer "Script executed successfully, but there are no results to show".
How can I print intermediate results such as those expected for 2nd part ?
I precise that concession & mission are both similar JSON objects.
I spent hours on this simple question. Please help.
var mission = db.mission.find({"googleCalendarEventId":"QiVJdbL"});
while (mission.hasNext()) {
var record = mission.next();
print(record.googleCalendarEventId + "," + record.concessionIdSet[0])
};
// 2nd part //
var concession = db.cursor.findOne({"_id": ObjectId(mission.concessionIdSet[0])});
while (concession.hasNext()) {
var record = concession.next();
print(record)
};

Thanks again #stennie, for others who would have the same issues, here's one code that worked for me and the 2 errors I committed :
1/ difference between find (--> cursor) and findOne (--> 1 element)
2/ actions in the loop had to be nested inside the loop --> I used a function and it works:
const missions = db.mission.find({
$and:[{"concessionToInvoice": {$exists: false}},
{"concessionIdSet":{$size:1}}]
});
missions.forEach((mission) => {
const concession = getConcession(mission);
print(mission.googleCalendarEventId+"- invoice to :"+concession.name);
mission.concessionToInvoice = getConcessionToInvoice(concession); //another function
db.mission.save(mission);
});
function getConcession(mission){
const concession = db.concession.findOne({"_id": ObjectId(mission.concessionIdSet[0])});
return concession;
}

Related

RavenDb Suggestions - return multiple-contexts words

I'm trying to get context based suggestions result from RavenDb, the purpose is ui dropdown with auto suggestion from large amount of data on server, each keystroke (in 400ms) is sent to retrieve suggestions.
The suggestion i need is with multiple words by context.
let's say i'm looking for 'Harry Potter', i have documents with just 'Harry' and some docs with only 'Potter', and documents with both.
But if i type 'harre poter' i would get one word suggestions.
i tried searching with multiple words (demonstrated here - suggest.Term = "(word1 word2)";), but the result is list of one words. i want to type 'harre poter' and get suggestion of 'Harry Potter'
i even tried querying multiple times with each word, but the result are not context based, in other word - there is no connection between them.
var words = text.Split(new String[] {" "}, StringSplitOptions.RemoveEmptyEntries).ToList();
var sugegstions = new List<SuggestionQuery>();
foreach (var word in words)
{
var suggest = new SuggestionQuery();
suggest.Field = "Body";
suggest.Term = word;
suggest.Popularity = true;
suggest.MaxSuggestions = 5;
suggest.Distance = StringDistanceTypes.Levenshtein;
sugegstions.Add(suggest);
}
var results = new List<SuggestionQueryResult>();
foreach (var suggest in sugegstions)
{
SuggestionQueryResult result =
s.Query<Book, Books_ByBody>().Suggest(suggest);
results.Add(result);
}
i looked in this SO question, and tried it too, but the results are the docs not suggestions.
my index is : `
public class Books_ByBody : AbstractIndexCreationTask
{
public Books_ByBody()
{
Map = books from book in books
select new
{
book.Body,
};
Indexes.Add(x => x.Body, FieldIndexing.Analyzed);
Suggestion(x => x.Body);
}
}
`

Get access to each element in object using push Leaflet and turfjs

I succeed to get intersection between line and polygon and display it on map. I had already post this issue here. Now I'm trying to display result for each line on console. When I tried to write console.log(result[i]) I got undefined. What is the right syntax I have to do, I tried many times. Here is my current code:
var lines = [line1, line2, line3, line4];
for (var i = 0; i < lines.length; i++) {
var intersection = [];
var result = [];
intersection = turf.intersect(lines[i], polygon1);
if (intersection) {
result.push(intersection);
L.geoJson(result, {
style: Style
}).addTo(map);
console.log(JSON.stringify(result[i]));
} else {
L.geoJson(lines[i]).addTo(map);
}
result is being defined inside your for loop which operates over lines...so why are you trying to use that loop's internal variable(meant for lines) on result, which only receives input from turf. I would think you just need console.log(result[0]), which would log your intersection.Secondly, I don't see the benefit of calling JSON.stringify for that console.log.

How to send (pass) variables from client to server (within the mapReduce function in server) in Meteor?

I am working on GeoSpatial project which I am using MongoDB as database and Meteor for creating my app. I have used mapReduce in my query. in order to visualize the result of query I put Google map API in the meteor. To make long story short, I want to get some location as an Input from meteor app and when I click on the button, see the result in Google Map API (which is placed in Meteor app.
Now my problem is that I cannot pass the variables (the ones that I got from textbox) from client function to server side in meteor.
Here is some part of my code in client side (here I have passed text1 and text2 as an argument in call function):
var text2 = document.getElementById("coords2").value;
var text1 = document.getElementById("coords1").value;
Meteor.call("doMapReducePointQuery", text1, text2, function(error, result){
if(error){
console.error(error)
}
else{
console.log("It works!");
}....// continued
and here is the part of the code in server side:
if (Meteor.isServer) {
Meteor.methods({
'doMapReducePointQuery': function(txt1,txt2) {
pxx=parseInt(txt1);
pyy=parseInt(txt2);
console.log(pxx); **// here I can see the pxx and pyy**
console.log(pyy);
var mapFn = function () { **// in this function I cannot get the pxx and pyy**
var px = -83.215; // here I just manually set the number, here where i want to get value from the text box and set it to px and py
var py = 41.53;
var key= this._id;
var value={
id:this._id,
type: this.type,
};
if (this.geometry.minlon <= px && px <= this.geometry.maxlon && this.geometry.minlat <= py && py <= this.geometry.maxlat) {
emit(key, value);
}
};
var reduceFn = function (key, value) { ....... // continued
As I mentioned in comments within the code, I can pass txt1 and txt2 to the doMapReducePointQuery method but the I cannot access then access the coordinates within my mapReduce mapFn function. I need to use txt1 (px) and txt2 (py) values in mapFn.
I did some research about how to make a variable, global in meteor, some of the people used "scope", but they did not mentioned how.
I would be really appreciated if somebody help me!

arc-jsapi How can I st_geometry using a lookup field?

I am using the st_geometry field and try to view the PNU code value.
I tried two ways.
oracle DB query.
select a.pnu from LP_PA_CBND_4600000000 a
where sde.st_contains(a.shape,
sde.st_point(177566.6728471977,160430.12935426735, 4))=1
When an event occurs, click the map object
i got the evt.mapPoint(x,y).
4 is my srid.
this way is took a long time. and query was down...
i used the arcgis api`s IdentifyParameters
my code is follows.
PoiClick : function(map, evt) {
G_evt =evt;
console.log("ClickPoint ==== "+evt.mapPoint);
var targetLayerId = 'LP_PA_CBND';
var url = map.Layers.getLayerInfo(targetLayerId).SVC_URL;
var map = map.getMap();
//파라미터 설정.
var idParams = new krcgis.core.tasks.IdentifyParameters();
G_idparams =idParams;
idParams.geometry = evt.mapPoint;
idParams.mapExtent = map.extent;
idParams.returnGeometry = true;
idParams.tolerance = 3;
idParams.layerOption = krcgis.core.tasks.IdentifyParameters.LAYER_OPTION_ALL;
idParams.width = map.width;
idParams.height = map.height;
krcgis.Function.GetPoiInfo(url, idParams);
return evt.mapPoint;
},
//POI 정보를 가져온다.
GetPoiInfo : function(url, idParams) {
idTask = new krcgis.core.tasks.IdentyfyTask(url);
idTask
.execute(idParams)
.addCallback(function (response) {
G_response = response;
if (response) {
return response;
}
})
.addErrback(function (error) {
console.log('GetPoiInfo result error=', error);
});
}
It could be obtained in this way code pnu.
However, this way is different from the value that gets pnu code depending on the zoom level.
I want to get a single pnu code in a single x, y values.
how to get pnu code?
Database table :
IdentifyTask can be a little tricky, because it takes into account zoom levels, therefor it doesn't always return the same results.
I suggest that you use QueryTask. Just one problem - it doesn't have tolerance parameter, but you can buffer your evt.mapPoint and get Polygon.

LinQ : when query will be executed

As per this link :http://msdn.microsoft.com/en-us/library/bb397906.aspx
namespace Linq
{
class IntroToLINQ
{
static void Main()
{
// The Three Parts of a LINQ Query:
// 1. Data source.
int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
// 2. Query creation.
// numQuery is an IEnumerable<int>
var numQuery =
from num in numbers
where (num % 2) == 0
select num;
// 3. Query execution.
foreach (int num in numQuery)
{
Console.Write("{0,1} ", num);
}
}
}
}
It states that query will not be exeucted , until data is iterated through foreach. But when I debugged , the data memeber of var(resultviews) contains the result values before the execution of foreach. Why this is happening?
Because your debugger is executing the query for you.
Linq is using something that is called Deferred Execution. Here is a good blog post that explains it: LINQ and Deferred Execution.
When you first execute the iterator, the query is processed and executed (in memory, to a database or in another way). Your debugger will do this for you.
Take for example the following code (you can paste this in a Console Application):
using System;
using System.Diagnostics;
using System.Linq;
namespace Stackoverflow
{
class Program
{
static void Main()
{
var numbers = Enumerable.Range(0, 100).ToList();
var filteredNumbers = from n in numbers
where n > 50
select n;
Debugger.Break();
foreach(int f in filteredNumbers)
{
Console.WriteLine(f);
}
}
}
}
When you look at filteredNumbers on the Debugger.Break() statement you will see the following:
The Results View options has the Value: "Expanding the Results View will enumerate the IEnumerable". And that's what's happening in the Debugger.
When you look at the variable with the debugger, Visual Studio is executing the iterator. That's why you see the results.
It's for the same reason that you should not put i++ in the watch window, because the code is actually executed.