Import JSON document array / object to a Meteor Collection with correct _ids [closed] - json

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What is the best way to import a 15,000 document json file of a format (but with a +30 foo fields)
[{"foo1":"foo1data1", "foo2":"foo2data1"}, {"foo1":"foo1data2", "foo2":"foo2data2"}...
{"foo1":"foo1dataN", "foo2":"foo2dataN"}])
to a Meteor collection?
I tried with mongoimport but that created ObjectID's instead of _id's and I could not make it work without autopublish, although other collections, created with Meteor, work just fine on client side.

Supposing the file is located on the server under pathToFile you can do something like this:
var fs = Npm.require("fs");
var Fiber = Npm.require("fibers");
fs.readFile(pathToFile, 'utf8', function (err, data) {
// handle error if there is some
data = JSON.parse(data);
Fiber(function () {
_.each(data, function (document) {
SomeMeteorCollection.insert(document);
});
}).run();
});
Please note that Fiber wrapper is required if you want call any meteor specific routines, for example collections API, within some nodejs asynchronous code.

Related

Angular 13: 415 Error Unsupported Media Type, on Delete [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
my Services.ts
deteleComentario(id: number): Observable<any>{
return this.http.delete(this.myAppUrl + this.myApiUrl + id);
}
my list-Comment-Component.ts
eliminarComentario(id: any ){
this.comentarioService.deteleComentario(id).subscribe(data => {
this.getComentarios();
}, error => {
console.log(error);
}
);
}
And my Api, NetCore with Mysql it`s work fine in GET, POST, GET{ID}, PUT{ID}, DELETE{ID}
any suggestion what could be the problem
The 415 Unsupported Media Type is a client-side error that indicates the request entity has a media type that the server or resource does not support. The response code may still be returned if the contents of the request body were not supported by the server. For example, a server might support specific JSON bodies, but the payload contents didn't validate, perhaps because it was missing a required property.
For example, the client uploads an image that was not in one of the formats (e.g., JPEG, PNG), or a video that is not in an accepted format (e.g., MPEG). The best way to fix it is to remove the image or video and upload a file in one of those formats.
Please see documentation for more information.

How should I go about parsing and using website data? I am using node js [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am using node js to create a bot that gets stats from r6.tracker.network, but when I load it in the data won't show up unlike when I have 'www.google.com' as the host. I don't really know where to go from here. I'm trying to use several different debugging methods, but I haven't found anything yet. There is no output.
function getWebpage(parameter){
const pathuser = '/profile/pc/' + parameter;
var http = require('http');
var options = {
host: 'r6.tracker.network',
path: '/'
}
var request = http.request(options, function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
console.log(data);
});
});
request.on('error', function (e) {
console.log(e.message);
});
request.end();
}
They are redirecting you to the https version of their site.
The key here is to add this logging:
console.log(res.statusCode);
console.log(res.headers.location);
When you do that, you will see this:
301
https://r6.tracker.network/
In other words, they want you to use the https version of their site and they are redirecting you to do that. You won't get the content of the web page from the http URL. You have to use https.
Coding takeaways here:
Always look at the http status and only proceed normally if you get a 2xx response.
Be prepared for 3xx redirect responses.
FYI, if you use a more modern library such as got() or any of the other libraries listed here, they will all follow redirects for you automatically and they will gather the full response for you automatically too. And, they use the more modern promise-based method of asynchronous programming. I'd really suggest you pick one of those libraries for your outbound http requests.

Using events.patch in Google Apps script [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm writing a Google apps script to update an event. I tried using the path API like below:
event_ins.setVisibility('private');
Logger.log('Making event %s %s private %s',calendarId, event_ins.summary, event_ins);
Calendar.Events.patch(event_ins,calendarId, eventID_ins);
I get the following error message:
11:28:30 AM Error HttpResponseException: Response Code: 404. Message: Not Found.
I tried using the update method instead
Calendar.Events.update(event_ins,calendarId,eventID_ins);
I'm still getting the same error.
The examples in Google's API documentation does not use Google script. I tried searching example code and I found similar usage. For instance this is from here :
event = Calendar.Events.patch(event, calendarId, eventId, {
sendNotifications: true
});
I would appreciate any help to get this working.

Get email using Hunter IO API with Google Apps Script [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Hello fellow developers,
I am trying to get the email count for any website using Hunter IO free API with Google Apps Script.
Hunter IO API reference : https://hunter.io/api/v2/docs#email-count
Here is my code.
function checkDomain() {
var domain = 'stripe.com';
var url = 'https://api.hunter.io/v2/email-count?domain='+domain;
var response = UrlFetchApp.fetch(domain);
var result = response.getContentText();
Logger.log(JSON.parse(result)); // <-- Line 56
}
I get this Error : SyntaxError: Unexpected token: < (line 56, file "Code")
Can anyone please help me understand this error and tell me how to retrieve a JSON response from this Hunter IO.
You need to pass url and not domain variables.
var response = UrlFetchApp.fetch(url);
I would also recommend the use of string constructors. Its increase readability and understanding of the code.
var domain = 'stripe.com';
var template = 'https://api.hunter.io/v2/email-count?domain=%s';
var url = Utilities.formatString(template, domain);

How do I get data from a web API? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm pretty basic at Perl, and I need to make a project for my university.
I want to download data from certain link, it is JSON data, so I know I have to use JSON::Parse module from CPAN.
But how to download content of link to my Perl variable? Should I use LWP get()?
Aren't you supposed to be learning Perl if it's a university project?
Anyway, your program will look something like this. It uses the LWP::Simple module to fetch the JSON data, and then JSON::Parse to process it into a Perl data structure
I've used printed the author value from each item of the array, as requested in your comment
use strict;
use warnings 'all';
use LWP::Simple 'get';
use JSON::Parse 'parse_json';
use constant URL => 'http://a.wykop.pl/observatory/entries/appkey,dJ4w7fXYpL';
my $json = get URL or die "Unable to get JSON data";
my $data = parse_json($json);
print "Authors:\n";
print " $_->{author}\n" for #$data;
output
Authors:
Snurq
AferaZaAfera
Devest
igorsped
Matt23
labla
poprawnie-niepoprawny
Parkero
Speed666
Xune
Gasior9
mikolajeq
Aztek2201
blogerbezbloga
Pan_wons
PanKaczucha
NieznanyAleAmbitny
dzika_kaczka_bez_dzioba
ilili
Bager
bmbcz01
hydrocyfolumpus
acarter
Doctor_Manhattan
strumienzgor